Tuesday, February 11, 2014

an example of authenticating when sending email from C# via System.Net.Mail

public void Send(string to, string message)
{
   MailMessage alert = new MailMessage("something@example.com", to);
   alert.Subject = "Communication!";
   alert.Body = message;
   NetworkCredential credentials = new NetworkCredential("something@example.com",
         "letmein");
   SmtpClient emailSender = new SmtpClient();
   emailSender.Host = "smtp.example.com";
   emailSender.UseDefaultCredentials = false;
   emailSender.Credentials = credentials;
   emailSender.Send(alert);
}

No comments:

Post a Comment