aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <zelent.marcin@gmail.com>2017-12-01 17:56:38 +0100
committermarcinzelent <zelent.marcin@gmail.com>2017-12-01 17:56:38 +0100
commit79bf391df757c50374a5acde3008860d48295926 (patch)
treeb11cbc30c006f5062f31acabc18f963280f8f850 /PollutometerWebApi/EmailSender.cs
parent7b1511ef9b0aa26d4591ff6cae60fb7377912ea7 (diff)
Added periodical checking of pollution and sending e-mail.
Diffstat (limited to 'PollutometerWebApi/EmailSender.cs')
-rw-r--r--PollutometerWebApi/EmailSender.cs40
1 files changed, 28 insertions, 12 deletions
diff --git a/PollutometerWebApi/EmailSender.cs b/PollutometerWebApi/EmailSender.cs
index 0e328c9..9effa47 100644
--- a/PollutometerWebApi/EmailSender.cs
+++ b/PollutometerWebApi/EmailSender.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Net.Mail;
namespace PollutometerWebApi
@@ -7,20 +8,35 @@ namespace PollutometerWebApi
{
public EmailSender() {}
- public static void SendEmail()
+ public static void SendEmail(string gasName, double max)
{
- MailMessage mail = new MailMessage("***REMOVED***", "***REMOVED***@edu.easj.dk");
- SmtpClient client = new SmtpClient()
+ try
{
- Host = "mail.cock.li",
- Port = 465,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new System.Net.NetworkCredential("***REMOVED***", "***REMOVED***")
- };
- mail.Subject = "this is a test email.";
- mail.Body = "this is my test email body";
- client.Send(mail);
+ MailMessage mail = new MailMessage("***REMOVED***", "***REMOVED***@edu.easj.dk");
+ 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" +
+ $"The warning was triggered by {gasName}. " +
+ $"Air quality index: {max}";
+ client.Send(mail);
+ }
+ catch(Exception ex)
+ {
+ Console.Write(ex.Message);
+ }
}
}
} \ No newline at end of file