sendEmail("Test Subject", "me@mail.com", "user1@mail.com,user2@mail.com,user3@mail.com", "Body of email", "", "",null);
public static bool sendEmail(string strSubject, string strFrom, string strTo, string strBody, string strCc, string strBcc,string displayName)
{
System.Net.Mail.SmtpClient Mail = new System.Net.Mail.SmtpClient();
Mail.Host = clsCommon.value("SMTPServer").ToString();
string username = null;
string Password = null;
Mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
username = "MailUserName";
Password = "MailPassword";
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(username, Password);
Mail.UseDefaultCredentials = false;
Mail.Credentials = basicAuthenticationInfo;
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
myMail.Subject = strSubject;
myMail.From = new System.Net.Mail.MailAddress(strFrom,displayName);
myMail.To.Add(new System.Net.Mail.MailAddress(strTo));
if (!string.IsNullOrEmpty(strCc))
{
myMail.CC.Add(new System.Net.Mail.MailAddress(strCc));
}
if (!string.IsNullOrEmpty(strBcc))
{
myMail.Bcc.Add(new System.Net.Mail.MailAddress(strBcc));
}
myMail.IsBodyHtml = true;
myMail.Body = strBody;
try
{
Mail.Send(myMail);
return true;
}
catch (Exception ex)
{
ex.Message.ToString();
return false;
}
}