Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. MailAddress from = new MailAddress("somemail@gmail.com", "Y");
  2. MailAddress to = new MailAddress("some@mail.ru");
  3. MailMessage m = new MailMessage(from, to);
  4. m.Subject = "Тест";
  5. m.Body = "<h2>Письмо</h2>";
  6. m.IsBodyHtml = true;
  7. SmtpClient smtp = new SmtpClient("localhost");
  8. smtp.EnableSsl = true;
  9. try
  10. {
  11. smtp.Send(m);
  12. }
  13. catch (Exception ex)
  14. {
  15. Console.WriteLine(ex.ToString());
  16. }
  17. Console.Read();
  18.  
  19. SmtpClient client = new SmtpClient();
  20. client.Port = 587;
  21. client.Host = "smtp.gmail.com";
  22. client.EnableSsl = true;
  23. client.Timeout = 10000;
  24. client.DeliveryMethod = SmtpDeliveryMethod.Network;
  25. client.UseDefaultCredentials = false;
  26. client.Credentials = new System.Net.NetworkCredential("user@gmail.com","password");
  27.  
  28. MailMessage mm = new MailMessage("donotreply@domain.com", "sendtomyemail@domain.co.uk", "test", "test");
  29. mm.BodyEncoding = UTF8Encoding.UTF8;
  30. mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  31.  
  32. client.Send(mm);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement