Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. public class Mail
  2. {
  3. private string user = "xxx@gmail.com";
  4. private string password = "password";
  5. public void sendEmail(string strTo, string strSubject, string strBody)
  6. {
  7. MailMessage objMailMessage = new MailMessage();
  8. System.Net.NetworkCredential objSMTPUserInfo = new System.Net.NetworkCredential();
  9. SmtpClient objSmtpClient = new SmtpClient();
  10.  
  11. objSmtpClient = new SmtpClient("smtp.web.de", 25);//port 25 or 587
  12. objSmtpClient.EnableSsl = true;
  13. objSmtpClient.Timeout = 10000;
  14. objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
  15. objSmtpClient.UseDefaultCredentials = false;
  16. objSmtpClient.Credentials = new System.Net.NetworkCredential(user, password);
  17.  
  18. objMailMessage.From = new MailAddress(user);
  19. objMailMessage.To.Add(new MailAddress(strTo));
  20. objMailMessage.Subject = strSubject;
  21. objMailMessage.Body = strBody;
  22.  
  23. try
  24. {
  25. objSmtpClient.Send(objMailMessage);
  26. }
  27. catch (Exception ex)
  28. {
  29. MessageBox.Show(ex.Message);
  30. }
  31.  
  32. finally
  33. {
  34. objMailMessage = null;
  35. objSMTPUserInfo = null;
  36. objSmtpClient = null;
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement