Advertisement
Guest User

Untitled

a guest
Feb 24th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. void SendEmail(string fromAddress, string toLine, string subject, string messageBody)
  2. {
  3. const string host = "smtp.server.com";
  4. const int port = 1234;
  5. const string userName = "(user)";
  6. const string password = "password";
  7.  
  8. using (var smtpClient = new SmtpClient(host, port))
  9. {
  10. smtpClient.Credentials = new NetworkCredential(userName, password);
  11.  
  12. var mailMessage = new MailMessage(fromAddress, toLine, subject, messageBody);
  13. smtpClient.Send(mailMessage);
  14. }
  15. }
  16.  
  17. private void SendEmailToAdmin(string message)
  18. {
  19. SmtpSection smtpSection = ConfigurationManager.GetSection("system.net/mailSettings/smtp") as SmtpSection;
  20. string host = smtpSection.Network.Host;
  21. if (string.IsNullOrEmpty(host))
  22. {
  23. host = "127.0.0.1";
  24. }
  25.  
  26. using (SmtpClient smtpClient = new SmtpClient(host, smtpSection.Network.Port))
  27. {
  28. MailMessage mail = new MailMessage(smtpSection.From, Properties.Settings.Default.SupportEmailAddress);
  29. mail.Subject = Environment.MachineName + ": Error";
  30. mail.IsBodyHtml = false;
  31. mail.Body = message;
  32. smtpClient.Send(mail);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement