123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using MailKit.Net.Smtp;
- using MimeKit;
- using System;
- using System.Linq;
- using System.Linq.Dynamic.Core;
- using UnivateProperties_API.Context;
- using UnivateProperties_API.Model.Communication;
-
- namespace UnivateProperties_API.Repository.Communication
- {
- public interface IMailRepository
- {
- void ContactUs(MailModel mm);
- void EnquireNow(MailModel mm);
- }
-
- public class MailRepository : IMailRepository
- {
- private readonly DataContext _dbContext;
-
- public MailRepository(DataContext db)
- {
- _dbContext = db;
- }
-
- MimeMessage messageObj = new MimeMessage();
- MailboxAddress from;
- MailboxAddress to;
- BodyBuilder bodyBuilder = new BodyBuilder();
- SmtpClient client = new SmtpClient();
-
- public void ContactUs(MailModel mm)
- {
- string property = mm.Property;
- string phone = mm.Phone;
- string name = mm.Name;
- string email = mm.Email;
- string message = mm.Message;
-
- from = new MailboxAddress("Admin", mm.FromAddress);
-
- to = new MailboxAddress("User", mm.ToAddress);
-
- messageObj.From.Add(from);
- messageObj.To.Add(to);
-
- messageObj.Subject = "Uni-Vate - New Contact Request";
-
- bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
- "<h4>Contact from: "+ name +"!</h4>" +
- "<h4>Email: "+ email +"</h4>" +
- "<h4>Phone: " + phone + "</h4>" +
- "<h4>Property: " + property + "</h4>" +
- "<div>" +
- "<h4>Message: </h4>" +
- "<p>" + message + "</p>" +
- "</div>" +
- "</div>" +
- "</div>";
-
- messageObj.Body = bodyBuilder.ToMessageBody();
-
- client.Connect("smtp.gmail.com", 465, true);
- client.Authenticate("jlouw365@gmail.com", "setskohatxpsceqo");
-
- client.Send(messageObj);
- client.Disconnect(true);
- client.Dispose();
- }
-
- public void EnquireNow(MailModel mm)
- {
- string phone = mm.Phone;
- string name = mm.Name;
- string email = mm.Email;
- string message = mm.Message;
- var props = _dbContext.Properties.ToList();
- var prop = props.Where(x => x.Id == Convert.ToInt32(mm.Property)).FirstOrDefault();
-
- from = new MailboxAddress("Admin", mm.FromAddress);
-
- to = new MailboxAddress("User", mm.ToAddress);
-
- messageObj.From.Add(from);
- messageObj.To.Add(to);
-
- messageObj.Subject = "Uni-Vate - Enquiry to view property";
-
- bodyBuilder.HtmlBody = "<div style=\"margin: 5px\">" +
- "<h4>Contact from: " + name + "!</h4>" +
- "<h4>Email: " + email + "</h4>" +
- "<h4>Phone: " + phone + "</h4>" +
- "<div>" +
- "<h4>Property: </h4>" +
- "<p>" + prop.Id + "</p>" +
- "<p>" + prop.PropertyName + "</p>" +
- "<p>" + prop.PropertyRef + "</p>" +
- "<p>" + prop.Price + "</p>" +
- "</div>" +
- "</div>" +
- "</div>";
-
- messageObj.Body = bodyBuilder.ToMessageBody();
-
- client.Connect("smtp.gmail.com", 465, true);
- client.Authenticate("jlouw365@gmail.com", "setskohatxpsceqo");
-
- client.Send(messageObj);
- client.Disconnect(true);
- client.Dispose();
- }
- }
- }
|