Send e-mail via SMTP using C#


SUBMITTED BY: inzi

DATE: March 30, 2017, 4:57 p.m.

FORMAT: C#

SIZE: 695 Bytes

HITS: 779

  1. Send e-mail via SMTP using C#
  2. using System.Net.Mail;
  3. using System.Text;
  4. ...
  5. // Command line argument must the the SMTP host.
  6. SmtpClient client = new SmtpClient();
  7. client.Port = 587;
  8. client.Host = "smtp.gmail.com";
  9. client.EnableSsl = true;
  10. client.Timeout = 10000;
  11. client.DeliveryMethod = SmtpDeliveryMethod.Network;
  12. client.UseDefaultCredentials = false;
  13. client.Credentials = new System.Net.NetworkCredential("user@gmail.com","password");
  14. MailMessage mm = new MailMessage("donotreply@domain.com", "sendtomyemail@domain.co.uk", "test", "test");
  15. mm.BodyEncoding = UTF8Encoding.UTF8;
  16. mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  17. client.Send(mm);

comments powered by Disqus