Guest User

Untitled

a guest
Oct 22nd, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. public static bool MailPassword(String email, String pwd)
  2. {
  3. try
  4. {
  5. MailMessage msg = new MailMessage
  6. {
  7. From = new MailAddress("admin@candidaturas.com")
  8. };
  9.  
  10. msg.To.Add(email);
  11. msg.Subject = "Password de Acesso";
  12. msg.Body = "A password de acesso para a sua conta é a seguinte: " + pwd;
  13. msg.IsBodyHtml = true;
  14.  
  15. SmtpClient smt = new SmtpClient
  16. {
  17. Host = Constants.Host,
  18. Port = Constants.Port
  19. };
  20.  
  21. System.Net.NetworkCredential ntwd = new NetworkCredential
  22. {
  23. UserName = Constants.Email,
  24. Password = Constants.Password
  25. };
  26.  
  27. smt.UseDefaultCredentials = false;
  28. smt.Credentials = ntwd;
  29. smt.EnableSsl = true;
  30. smt.Send(msg);
  31.  
  32. return true;
  33. }
  34. catch(SmtpFailedRecipientsException smtpe)
  35. {
  36. Console.WriteLine("Error: {0}", smtpe.StatusCode);
  37. return false;
  38. }
  39. catch (SmtpException smtpe)
  40. {
  41. Console.WriteLine("Error: {0}", smtpe.StatusCode);
  42. return false;
  43. }
  44. catch (Exception e)
  45. {
  46. Console.WriteLine("Exception caught in RetryIfBusy(): {0}", e.ToString());
  47. return false;
  48. }
  49. }
Add Comment
Please, Sign In to add comment