Skip to content

Instantly share code, notes, and snippets.

@davidalencar
Created July 2, 2013 13:05
Show Gist options
  • Save davidalencar/5909139 to your computer and use it in GitHub Desktop.
Save davidalencar/5909139 to your computer and use it in GitHub Desktop.
Sending e-mail via .NET framework. Server with authentication SSL
private void sendEmail()
{
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Host = "smtp.domain.com";
client.Port = 587;
// setup Smtp authentication
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential("user@domain.com", "password");
client.UseDefaultCredentials = false;
client.Credentials = credentials;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("email_From@tdomain.com");
msg.To.Add(new MailAddress("email_To@domain.com"));
msg.Subject = "This is a test Email subject";
msg.IsBodyHtml = true;
msg.Body = string.Format("<html><head></head><body><b>Test HTML Email</b></body>");
try
{
client.Send(msg);
MessageBox.Show("Your message has been successfully sent.");
}
catch (Exception ex)
{
MessageBox.Show("Error occured while sending your message." + ex.Message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment