Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. MailAddress to = new MailAddress(errorEmailTo);
  2. MailAddress from = new MailAddress(mailFrom);
  3.  
  4. using (MailMessage mail = new MailMessage(from.Address, to.Address))
  5. {
  6. SmtpClient client = new SmtpClient();
  7. NetworkCredential credentials = new NetworkCredential(mailUser, mailPassword);
  8. try
  9. {
  10. client.Host = mailHost;
  11. client.Port = port;
  12. if (enableSSL == "Y")
  13. {
  14. client.EnableSsl = true;
  15. }
  16. client.UseDefaultCredentials = false;
  17. client.Credentials = credentials;
  18. //client.DeliveryMethod = SmtpDeliveryMethod.Network;
  19. mail.Subject = "Test Message. Client ID: " + clientID;
  20. mail.Body = "Please find the message from BTC Client ID Title: "
  21. + clientIDTitle
  22. + " "
  23. + msg;
  24.  
  25. client.Send(mail);
  26.  
  27. MessageBox.Show("Sent email to " + errorEmailTo + "n Enable SSL = " + enableSSL);
  28. button1.BackColor = Color.GreenYellow;
  29. }
  30. catch (Exception ex)
  31. {
  32. button1.BackColor = Color.Red;
  33.  
  34. MessageBox.Show("ERROR. Cannot send email to " + errorEmailTo + " Error Message: " + ex.Message
  35. + "nEnable SSL = " + enableSSL
  36. + "nExc. Type = " + ex.GetType().ToString()
  37. + "nStack Trace = " + ex.StackTrace
  38. + "n");
  39.  
  40. }
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. ERROR. Cannot send email to xxxx Error Message: Failure sending mail.
  48. Enable SSL = Y
  49. Exc. Type = System.Net.Mail.SmtpException
  50. Stack Trace = at System.Net.Mail.SmtpClient.Send(MailMessage message)
  51.  
  52. at BTCClientUtilities.Form1.SendEmailTo(String errorEmailTo, String msg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement