From b7757c89b6576cfc33579f1dec118086e159e03e Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Fri, 1 Dec 2017 14:56:49 +0100 Subject: Added method for sending e-mail. --- PollutometerWebApi/EmailSender.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 PollutometerWebApi/EmailSender.cs (limited to 'PollutometerWebApi/EmailSender.cs') diff --git a/PollutometerWebApi/EmailSender.cs b/PollutometerWebApi/EmailSender.cs new file mode 100644 index 0000000..0e328c9 --- /dev/null +++ b/PollutometerWebApi/EmailSender.cs @@ -0,0 +1,26 @@ +using System; +using System.Net.Mail; + +namespace PollutometerWebApi +{ + public class EmailSender + { + public EmailSender() {} + + public static void SendEmail() + { + MailMessage mail = new MailMessage("***REMOVED***", "***REMOVED***@edu.easj.dk"); + SmtpClient client = new SmtpClient() + { + 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); + } + } +} \ No newline at end of file -- cgit v1.2.3 From 79bf391df757c50374a5acde3008860d48295926 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Fri, 1 Dec 2017 17:56:38 +0100 Subject: Added periodical checking of pollution and sending e-mail. --- PollutometerWebApi/EmailSender.cs | 40 +++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'PollutometerWebApi/EmailSender.cs') 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 = "

WARNING!

\n" + + "\n" + + "\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 -- cgit v1.2.3 From 644d63b7073f59290029bf084fb57db5a501309d Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Fri, 1 Dec 2017 18:07:59 +0100 Subject: Fixed e-mail layout. --- PollutometerWebApi/EmailSender.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'PollutometerWebApi/EmailSender.cs') diff --git a/PollutometerWebApi/EmailSender.cs b/PollutometerWebApi/EmailSender.cs index 9effa47..6d8702e 100644 --- a/PollutometerWebApi/EmailSender.cs +++ b/PollutometerWebApi/EmailSender.cs @@ -29,8 +29,8 @@ namespace PollutometerWebApi "\n" + "\n" + "\n" + - $"The warning was triggered by {gasName}. " + - $"Air quality index: {max}"; + $"

The warning was triggered by {gasName}.

\n" + + $"

Air quality index: {max}

"; client.Send(mail); } catch(Exception ex) -- cgit v1.2.3 From a3ad4472de9096ec0a12d15097048578b3514d4b Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Mon, 4 Dec 2017 10:14:32 +0100 Subject: Improved calculating of AQI and sending e-mail. --- PollutometerWebApi/EmailSender.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'PollutometerWebApi/EmailSender.cs') diff --git a/PollutometerWebApi/EmailSender.cs b/PollutometerWebApi/EmailSender.cs index 6d8702e..287551e 100644 --- a/PollutometerWebApi/EmailSender.cs +++ b/PollutometerWebApi/EmailSender.cs @@ -1,17 +1,13 @@ using System; -using System.Collections.Generic; using System.Net.Mail; +using PollutometerWebApi.Models; namespace PollutometerWebApi { - public class EmailSender + public static class EmailSender { - public EmailSender() {} - - public static void SendEmail(string gasName, double max) + public static void SendEmail(Aqi aqi) { - try - { MailMessage mail = new MailMessage("***REMOVED***", "***REMOVED***@edu.easj.dk"); SmtpClient client = new SmtpClient() { @@ -29,14 +25,9 @@ namespace PollutometerWebApi "\n" + "\n" + "\n" + - $"

The warning was triggered by {gasName}.

\n" + - $"

Air quality index: {max}

"; + $"

The warning was triggered by {aqi.GasName}.

\n" + + $"

Air quality index: {aqi.Value}

"; client.Send(mail); - } - catch(Exception ex) - { - Console.Write(ex.Message); - } } } } \ No newline at end of file -- cgit v1.2.3 From e41a7bee10dbb968913429c5d0e4a1fcbbb5b5e3 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Mon, 4 Dec 2017 12:38:28 +0100 Subject: Changed e-mail address. --- PollutometerWebApi/EmailSender.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'PollutometerWebApi/EmailSender.cs') diff --git a/PollutometerWebApi/EmailSender.cs b/PollutometerWebApi/EmailSender.cs index 287551e..f62a9ca 100644 --- a/PollutometerWebApi/EmailSender.cs +++ b/PollutometerWebApi/EmailSender.cs @@ -8,7 +8,7 @@ namespace PollutometerWebApi { public static void SendEmail(Aqi aqi) { - MailMessage mail = new MailMessage("***REMOVED***", "***REMOVED***@edu.easj.dk"); + MailMessage mail = new MailMessage("***REMOVED***", "alek2026@edu.easj.dk"); SmtpClient client = new SmtpClient() { Host = "mail.cock.li", -- cgit v1.2.3 From 54d1019413958e0ba24b85007c1f5f97ca19a0b3 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Mon, 4 Dec 2017 13:01:04 +0100 Subject: Added levels of AQI. --- PollutometerWebApi/EmailSender.cs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'PollutometerWebApi/EmailSender.cs') diff --git a/PollutometerWebApi/EmailSender.cs b/PollutometerWebApi/EmailSender.cs index f62a9ca..6cc60fc 100644 --- a/PollutometerWebApi/EmailSender.cs +++ b/PollutometerWebApi/EmailSender.cs @@ -8,26 +8,27 @@ namespace PollutometerWebApi { public static void SendEmail(Aqi aqi) { - MailMessage mail = new MailMessage("***REMOVED***", "alek2026@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 = "

WARNING!

\n" + - "\n" + - "\n" + - "\n" + + MailMessage mail = new MailMessage("***REMOVED***", "alek2026@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 = "

WARNING!

\n" + + "\n" + + "\n" + + "\n" + $"

The warning was triggered by {aqi.GasName}.

\n" + - $"

Air quality index: {aqi.Value}

"; - client.Send(mail); + $"

Air quality index: {aqi.Value}

" + + $"

The AQI level is {aqi.Level}!"; + client.Send(mail); } } } \ No newline at end of file -- cgit v1.2.3