Advertisement
Guest User

MessageService

a guest
Jul 26th, 2017
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Mail;
  7. using System.Threading.Tasks;
  8. using System.Web;
  9.  
  10. namespace thePure5.Models
  11. {
  12. public class OrderServices
  13. {
  14.  
  15. public async static Task OrderNowAsync(string email, string subject, string message)
  16. {
  17.  
  18. try
  19. {
  20.  
  21. var _email = "magdalena.kkirova@gmail.com";
  22. var _epass = ConfigurationManager.AppSettings["EmailPassword"];
  23. var _dispName = "Order Form";
  24. MailMessage myMessage = new MailMessage();
  25. myMessage.To.Add("magdalena.kkirova@gmail.com");
  26. myMessage.From = new MailAddress(_email, _dispName);
  27. myMessage.Subject = subject;
  28. myMessage.Body = message;
  29. myMessage.IsBodyHtml = true;
  30.  
  31. using (SmtpClient smtp = new SmtpClient())
  32. {
  33. smtp.EnableSsl = true;
  34. smtp.Host = "smtp.gmail.com"; //if using hotmail to send emails
  35. smtp.Port = 587;
  36. smtp.UseDefaultCredentials = false;
  37. smtp.Credentials = new NetworkCredential(_email, _epass);
  38. smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  39. smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
  40. await smtp.SendMailAsync(myMessage);
  41. }
  42. }
  43. catch (Exception ex)
  44. {
  45. throw ex;
  46. }
  47. }
  48.  
  49. public async static Task SendBulkEmailAsync(string[] emails, string subject, string message, List<HttpPostedFileBase> attachments)
  50. {
  51. try
  52. {
  53. var _email = "magdalena.kkirova@gmail.com";
  54. var _epass = ConfigurationManager.AppSettings["EmailPassword"];
  55. var _dispName = "DisplayName";
  56. MailMessage myMessage = new MailMessage();
  57.  
  58. myMessage.From = new MailAddress(_email, _dispName);
  59. myMessage.Subject = subject;
  60. myMessage.Body = message;
  61. myMessage.IsBodyHtml = true;
  62.  
  63. using (SmtpClient smtp = new SmtpClient())
  64. {
  65. smtp.EnableSsl = true;
  66. smtp.Host = "smtp.gmail.com"; //if using hotmail to send emails
  67. smtp.Port = 465;
  68. smtp.UseDefaultCredentials = false;
  69. smtp.Credentials = new NetworkCredential(_email, _epass);
  70. smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
  71. smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
  72. await smtp.SendMailAsync(myMessage);
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. throw ex;
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement