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 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }
  10. public class MailRepository : IMailRepository
  11. {
  12. MimeMessage messageObj = new MimeMessage();
  13. MailboxAddress from;
  14. MailboxAddress to;
  15. BodyBuilder bodyBuilder = new BodyBuilder();
  16. SmtpClient client = new SmtpClient();
  17. public void ContactUs(MailModel mm)
  18. {
  19. string property = mm.Property;
  20. string phone = mm.Phone;
  21. string name = mm.Name;
  22. string email = mm.Email;
  23. string message = mm.Message;
  24. from = new MailboxAddress("Admin", mm.FromAddress);
  25. to = new MailboxAddress("User", mm.ToAddress);
  26. messageObj.From.Add(from);
  27. messageObj.To.Add(to);
  28. messageObj.Subject = "Uni-Vate - New Contact Request";
  29. bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
  30. "<h4>Contact from: "+ name +"!</h4>" +
  31. "<h4>Email: "+ email +"</h4>" +
  32. "<h4>Phone: " + phone + "</h4>" +
  33. "<h4>Property: " + property + "</h4>" +
  34. "<div>" +
  35. "<h4>Message: </h4>" +
  36. "<p>" + message + "</p>" +
  37. "</div>" +
  38. "</div>" +
  39. "</div>";
  40. messageObj.Body = bodyBuilder.ToMessageBody();
  41. client.Connect("smtp.gmail.com", 465, true);
  42. client.Authenticate("jlouw365@gmail.com", "setskohatxpsceqo");
  43. client.Send(messageObj);
  44. client.Disconnect(true);
  45. client.Dispose();
  46. }
  47. }
  48. }