From 3f4c0720e1e3421431e7baa20882a4a4512a7fab Mon Sep 17 00:00:00 2001 From: ivar Date: Sun, 19 Oct 2025 23:41:23 +0200 Subject: Initial --- src/Utilities/Email.cs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/Utilities/Email.cs (limited to 'src/Utilities/Email.cs') diff --git a/src/Utilities/Email.cs b/src/Utilities/Email.cs new file mode 100644 index 0000000..248db32 --- /dev/null +++ b/src/Utilities/Email.cs @@ -0,0 +1,56 @@ +using System; +using System.Net.Mail; +using System.Net; + +namespace IOL.Fagprove.Utilities +{ + public class Email + { + public string Recepient { get; set; } + public string Message { get; set; } + public string Title { get; set; } + public bool Valid { get; private set; } + public bool Sent { get; private set; } + + public bool Send() + { + if (!Validate()) return false; + var client = new SmtpClient("smtp.server.com", 587) + { + EnableSsl = true, + Credentials = new NetworkCredential("user", "pass") + }; + var from = new MailAddress("bot@bottesen.no", "Hal", System.Text.Encoding.UTF8); + var to = new MailAddress(Recepient); + var message = new MailMessage(from, to) + { + Body = Message, + BodyEncoding = System.Text.Encoding.UTF8, + Subject = Title, + SubjectEncoding = System.Text.Encoding.UTF8 + }; +#if DEBUG + Console.WriteLine(Message); +#else + client.Send(message); +#endif + Sent = true; + return true; + } + + private bool Validate() + { + if (Recepient.IsMissing() + || Title.IsMissing() + || Message.IsMissing() + || !Recepient.IsEmail()) + { + Valid = false; + return false; + } + + Valid = true; + return true; + } + } +} \ No newline at end of file -- cgit v1.3