summaryrefslogtreecommitdiffstats
path: root/src/Utilities/Email.cs
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-19 23:41:23 +0200
committerivar <i@oiee.no>2025-10-19 23:41:23 +0200
commit3f4c0720e1e3421431e7baa20882a4a4512a7fab (patch)
tree734ca81d7d0841d8863e3f523ebba14c282dc681 /src/Utilities/Email.cs
downloadfagprove-3f4c0720e1e3421431e7baa20882a4a4512a7fab.tar.xz
fagprove-3f4c0720e1e3421431e7baa20882a4a4512a7fab.zip
InitialHEADmaster
Diffstat (limited to 'src/Utilities/Email.cs')
-rw-r--r--src/Utilities/Email.cs56
1 files changed, 56 insertions, 0 deletions
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