public void Send()
{
MailMessage emailMessage;
emailMessage = new MailMessage();
emailMessage.From = new MailAddress(m_from);
emailMessage.Subject = m_subject;
emailMessage.Body = m_body;
emailMessage.IsBodyHtml = m_isBodyHtml;
// Add the specified To recipients for the mail message.
if (!string.IsNullOrEmpty(m_toRecipients))
{
foreach (string toRecipient in m_toRecipients.Split(';', ','))
emailMessage.To.Add(toRecipient.Trim());
}
if (!string.IsNullOrEmpty(m_ccRecipients))
{
// Add the specified CC recipients for the mail message.
foreach (string ccRecipient in m_ccRecipients.Split(';', ','))
emailMessage.CC.Add(ccRecipient.Trim());
}
if (!string.IsNullOrEmpty(m_bccRecipients))
{
// Add the specified BCC recipients for the mail message.
foreach (string bccRecipient in m_bccRecipients.Split(';', ','))
emailMessage.Bcc.Add(bccRecipient.Trim());
}
if (!string.IsNullOrEmpty(m_attachments))
{
// Attach the specified files to the mail message.
foreach (string attachment in m_attachments.Split(';', ','))
{
// Create the file attachment for the mail message.
Attachment data = new Attachment(attachment.Trim(), MediaTypeNames.Application.Octet);
ContentDisposition header = data.ContentDisposition;
// Add time stamp information for the file.
header.CreationDate = File.GetCreationTime(attachment);
header.ModificationDate = File.GetLastWriteTime(attachment);
header.ReadDate = File.GetLastAccessTime(attachment);
emailMessage.Attachments.Add(data); // Attach the file.
}
}
try
{
// Send the mail.
m_smtpClient.Send(emailMessage);
}
finally
{
// Clean-up.
emailMessage.Dispose();
}
}
Mail::Send ( string from, string toRecipients, string subject, string body, bool isBodyHtml, string smtpServer ) : void | |
Mail::Send ( string from, string toRecipients, string subject, string body, bool isBodyHtml, string attachments, string smtpServer ) : void | |
Mail::Send ( string from, string toRecipients, string subject, string body, bool isBodyHtml, string smtpServer, string username, |
|
Mail::Send ( string from, string toRecipients, string subject, string body, bool isBodyHtml, string smtpServer, string username, |
|
Mail::Send ( string from, string toRecipients, string subject, string body, bool isBodyHtml, string smtpServer, string username, string password ) : void | |
Mail::Send ( string from, string toRecipients, string subject, string body, bool isBodyHtml, string smtpServer, string username, string password, bool enableSSL ) : void | |
Mail::Send ( string from, string toRecipients, string ccRecipients, string bccRecipients, string subject, string body, bool isBodyHtml, string smtpServer ) : void | |
Mail::Send ( string from, string toRecipients, string ccRecipients, string bccRecipients, string subject, string body, bool isBodyHtml, string attachments, string smtpServer ) : void |
/// <summary> /// Sends a secure <see cref="Mail"/> message. /// </summary> /// <param name="from">The e-mail address of the <see cref="Mail"/> message sender.</param> /// <param name="toRecipients">A comma-separated or semicolon-separated e-mail address list of the <see cref="Mail"/> message recipients.</param> /// <param name="subject">The subject of the <see cref="Mail"/> message.</param> /// <param name="body">The body of the <see cref="Mail"/> message.</param> /// <param name="isBodyHtml">true if the <see cref="Mail"/> message body is to be formated as HTML; otherwise false.</param> /// <param name="smtpServer">The name or IP address of the SMTP server to be used for sending the <see cref="Mail"/> message.</param> /// <param name="username">The username of the account used to authenticate to the SMTP server.</param> /// <param name="password">The password of the account used to authenticate to the SMTP server.</param> /// <param name="enableSSL">The flag that determines whether to use SSL when communicating with the SMTP server.</param> public static void Send(string from, string toRecipients, string subject, string body, bool isBodyHtml, string smtpServer, string username, SecureString password, bool enableSSL) { using (Mail email = new Mail(from, toRecipients, smtpServer)) { email.Subject = subject; email.Body = body; email.IsBodyHtml = isBodyHtml; email.Username = username; email.SecurePassword = password; email.EnableSSL = enableSSL; email.Send(); } }