Guest User

Untitled

a guest
Nov 1st, 2017
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. MailMessage mail = new MailMessage();
  2. mail.From = new MailAddress("login@yandex.ru", "Name");
  3. mail.To.Add(account.Email);
  4. mail.Subject = "Hello";
  5. mail.Body = "Hello from Asp.net mvc";
  6. mail.IsBodyHtml = true;
  7. SmtpClient client = new SmtpClient();
  8. client.Host = "smtp.yandex.ru";
  9. client.Port = 587;
  10. client.Credentials = new NetworkCredential("login@yandex.ru","password");
  11.  
  12. client.Send(mail);
  13.  
  14. db.Registration.Add(account);
  15. db.SaveChanges();
  16.  
  17. public static void SendEmail(string email, string text, string subject)
  18. {
  19. MailAddress from = new MailAddress("aspnet.confirmation@yandex.ru", "ASP.NET Blog");
  20. MailAddress to = new MailAddress(email);
  21. MailMessage message = new MailMessage(from, to);
  22. message.Subject = subject;
  23. message.Body = text;
  24. message.IsBodyHtml = true;
  25. SmtpClient smtp = new SmtpClient("smtp.yandex.ru", 25);
  26. smtp.Credentials = new System.Net.NetworkCredential("aspnet.confirmation@yandex.ru", "yourpassword");
  27. smtp.EnableSsl = true;
  28. smtp.Send(message);
  29. }
  30.  
  31. public static void SendEmail(string title, string text, string emailTo, bool isBodyHtml = false)
  32. {
  33. try
  34. {
  35. MailMessage mail = new MailMessage();
  36. mail.IsBodyHtml = isBodyHtml;
  37. mail.From = new MailAddress(ConstantsWeb.Email.Address.RobotEmail, ConstantsWeb.Global.CompanyName);
  38. mail.To.Add(emailTo);
  39. mail.Subject = title;
  40. mail.Body = text;
  41. mail.SubjectEncoding = Encoding.GetEncoding("utf-8");
  42. mail.Priority = MailPriority.Normal;
  43. SmtpClient SmtpServer = new SmtpClient(ConstantsWeb.Email.Server.Name)
  44. {
  45. Credentials = new NetworkCredential(ConstantsWeb.Email.Address.RobotEmail, ConstantsWeb.Email.Address.RobotEmailPassword),
  46. Port = ConstantsWeb.Email.Server.Port,
  47. EnableSsl = ConstantsWeb.Email.Server.UseSsl
  48. };
  49.  
  50. SmtpServer.Send(mail);
  51. }
  52. catch(Exception e)
  53. {
  54. //do whatever...
  55. }
  56. }
Add Comment
Please, Sign In to add comment