1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
string mailFrom = "....";
string SmtpClient = ".....";
string username = "......";
string password = "......";
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential(username, password);
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(mailFrom);
smtpClient.Host = SmtpClient;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
smtpClient.EnableSsl = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Timeout = 5000;
smtpClient.Port = 587;// 465;
message.From = fromAddress;
message.Subject = "your subject";
//Set IsBodyHtml to true means you can send HTML email.
message.IsBodyHtml = true;
message.Body = "<h1>your message body</h1>";
message.To.Add(mailTo);
try
{
smtpClient.Send(message);
return true;
}
catch (Exception ex)
{
//Error, could not send the message
CurrentContext.Message.Display(ex.Message + "\n" + ex.StackTrace);
return false;
} |