Guest User

Untitled

a guest
Jul 20th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. using System.Net.Mail;
  2.  
  3. var fromAddress = new MailAddress("from@gmail.com", "From Name");
  4. var toAddress = new MailAddress("to@example.com", "To Name");
  5. const string fromPassword = "fromPassword";
  6. const string subject = "Subject";
  7. const string body = "Body";
  8.  
  9. var smtp = new SmtpClient
  10. {
  11. Host = "smtp.gmail.com",
  12. Port = 587,
  13. EnableSsl = true,
  14. DeliveryMethod = SmtpDeliveryMethod.Network,
  15. UseDefaultCredentials = false,
  16. Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  17. };
  18. using (var message = new MailMessage(fromAddress, toAddress)
  19. {
  20. Subject = subject,
  21. Body = body
  22. })
  23. {
  24. smtp.Send(message);
  25. }
Add Comment
Please, Sign In to add comment