API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MailRepository.cs 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using MailKit.Net.Smtp;
  2. using MimeKit;
  3. using UnivateProperties_API.Model.Communication;
  4. namespace UnivateProperties_API.Repository.Communication
  5. {
  6. public interface IMailRepository
  7. {
  8. void ContactUs(MailModel mm);
  9. void EnquireNow(MailModel mm);
  10. }
  11. public class MailRepository : IMailRepository
  12. {
  13. MimeMessage messageObj = new MimeMessage();
  14. MailboxAddress from;
  15. MailboxAddress to;
  16. BodyBuilder bodyBuilder = new BodyBuilder();
  17. SmtpClient client = new SmtpClient();
  18. public void ContactUs(MailModel mm)
  19. {
  20. string property = mm.Property;
  21. string phone = mm.Phone;
  22. string name = mm.Name;
  23. string email = mm.Email;
  24. string message = mm.Message;
  25. from = new MailboxAddress("Admin", mm.FromAddress);
  26. to = new MailboxAddress("User", mm.ToAddress);
  27. messageObj.From.Add(from);
  28. messageObj.To.Add(to);
  29. messageObj.Subject = "Uni-Vate - New Contact Request";
  30. bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
  31. "<h4>Contact from: "+ name +"!</h4>" +
  32. "<h4>Email: "+ email +"</h4>" +
  33. "<h4>Phone: " + phone + "</h4>" +
  34. "<h4>Property: " + property + "</h4>" +
  35. "<div>" +
  36. "<h4>Message: </h4>" +
  37. "<p>" + message + "</p>" +
  38. "</div>" +
  39. "</div>" +
  40. "</div>";
  41. messageObj.Body = bodyBuilder.ToMessageBody();
  42. client.Connect("smtp.gmail.com", 465, true);
  43. client.Authenticate("jlouw365@gmail.com", "setskohatxpsceqo");
  44. client.Send(messageObj);
  45. client.Disconnect(true);
  46. client.Dispose();
  47. }
  48. public void EnquireNow(MailModel mm)
  49. {
  50. string phone = mm.Phone;
  51. string name = mm.Name;
  52. string email = mm.Email;
  53. string message = mm.Message;
  54. from = new MailboxAddress("Admin", mm.FromAddress);
  55. to = new MailboxAddress("User", mm.ToAddress);
  56. messageObj.From.Add(from);
  57. messageObj.To.Add(to);
  58. messageObj.Subject = "Uni-Vate - Enquiry to view property";
  59. bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
  60. "<h4>Contact from: " + name + "!</h4>" +
  61. "<h4>Email: " + email + "</h4>" +
  62. "<h4>Phone: " + phone + "</h4>" +
  63. "<div>" +
  64. "<h4>Message: </h4>" +
  65. "<p>" + message + "</p>" +
  66. "</div>" +
  67. "</div>" +
  68. "</div>";
  69. messageObj.Body = bodyBuilder.ToMessageBody();
  70. client.Connect("smtp.gmail.com", 465, true);
  71. client.Authenticate("jlouw365@gmail.com", "setskohatxpsceqo");
  72. client.Send(messageObj);
  73. client.Disconnect(true);
  74. client.Dispose();
  75. }
  76. }
  77. }