diff options
Diffstat (limited to 'pollutometer-api/PollutometerWebApi/EmailSender.cs')
-rw-r--r-- | pollutometer-api/PollutometerWebApi/EmailSender.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pollutometer-api/PollutometerWebApi/EmailSender.cs b/pollutometer-api/PollutometerWebApi/EmailSender.cs new file mode 100644 index 0000000..266f146 --- /dev/null +++ b/pollutometer-api/PollutometerWebApi/EmailSender.cs @@ -0,0 +1,34 @@ +using System; +using System.Net.Mail; +using PollutometerWebApi.Models; + +namespace PollutometerWebApi +{ + public static class EmailSender + { + public static void SendEmail(Aqi aqi) + { + MailMessage mail = new MailMessage("***REMOVED***", "<PUT E-MAIL HERE>"); + SmtpClient client = new SmtpClient() + { + Host = "mail.cock.li", + Port = 587, + EnableSsl = true, + Timeout = 100, + DeliveryMethod = SmtpDeliveryMethod.Network, + UseDefaultCredentials = false, + Credentials = new System.Net.NetworkCredential("***REMOVED***", "***REMOVED***") + }; + mail.Subject = $"Pollutometer warning - {DateTime.Now}"; + mail.IsBodyHtml = true; + mail.Body = "<h3>WARNING!</h3>\n" + + "\n" + + "<img src=\"https://i.imgflip.com/20b4q2.jpg\"/>\n" + + "\n" + + $"<p>The warning was triggered by {aqi.GasName}.</p>\n" + + $"<p>Air quality index: {aqi.Value}</p>" + + $"<p>The AQI level is {aqi.Level}!"; + client.Send(mail); + } + } +} |