Guest User

Untitled

a guest
Nov 20th, 2017
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. public ViewResult Index(MailModel objectMailModel)
  2. {
  3. if (ModelState.IsValid)
  4. {
  5. int count = 0;
  6. if (objectMailModel.To.Contains(";"))
  7. {
  8. string[] str = objectMailModel.To.ToString().Split(';');
  9. count = str.Length;
  10. for (int i = 0; i < count; i++)
  11. {
  12. MailMessage mail = new MailMessage();
  13. mail.To.Add(str[i]);
  14. mail.From = new MailAddress("hare.b@kencloud.co.in");
  15. mail.Subject = objectMailModel.Subject;
  16. mail.Body = objectMailModel.Body;
  17. mail.IsBodyHtml = true;
  18. SmtpClient smtp = new SmtpClient("smtp-mail.outlook.com");
  19. //smtp.Host = "smtp.gmail.com";
  20. smtp.Host = "smtp.live.com";
  21. smtp.Port = 587;
  22. smtp.Credentials = new System.Net.NetworkCredential("hare.b@kencloud.co.in", "***********");
  23. smtp.EnableSsl = true;
  24. smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  25.  
  26. smtp.Send(mail);
  27. ViewBag.Message = "Sent";
  28. }
  29. return View("Index", objectMailModel);
  30. }
  31. else
  32. {
  33. MailMessage mail = new MailMessage();
  34. mail.To.Add(objectMailModel.To);
  35. mail.From = new MailAddress("hare.b@kencloud.co.in");
  36. mail.Subject = objectMailModel.Subject;
  37. mail.Body = objectMailModel.Body;
  38. mail.IsBodyHtml = true;
  39. SmtpClient smtp = new SmtpClient("smtp-mail.outlook.com");
  40. smtp.Host = "smtp.live.com";
  41. smtp.Port = 587;
  42. smtp.UseDefaultCredentials = true;
  43. smtp.Credentials = new System.Net.NetworkCredential("hare.b@kencloud.co.in", "***********");
  44. smtp.EnableSsl = true;
  45. smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  46. smtp.Send(mail);
  47. ViewBag.Message = "Sent";
  48. return View("Index", objectMailModel);
  49. }
  50. }
  51. else
  52. {
  53. return View();
  54. }
  55. }
Add Comment
Please, Sign In to add comment