aboutsummaryrefslogtreecommitdiff
path: root/email_helper.py
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2020-09-20 01:07:23 +0000
committerMark Powers <mark@marks.kitchen>2020-09-20 01:07:23 +0000
commitb4441232cb2c54e7ab0173a09640eff3828017cd (patch)
tree459d422f093c5de07173469689ecc705a1ef7286 /email_helper.py
Initial commit
Diffstat (limited to 'email_helper.py')
-rw-r--r--email_helper.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/email_helper.py b/email_helper.py
new file mode 100644
index 0000000..d3edfb8
--- /dev/null
+++ b/email_helper.py
@@ -0,0 +1,28 @@
+import smtplib
+from email.mime.text import MIMEText
+from email.utils import formatdate
+
+from config import config
+
+def send(frm, name, to, subject, body, subtype="plain"):
+ """Send a email to the given address, from the given address and name with the subject and body
+ """
+ try:
+ server = smtplib.SMTP(config["email"]["server"], int(config["email"]["port"]))
+ server.ehlo()
+ server.starttls()
+ server.login(config["email"]["user"], config["email"]["pass"])
+
+ frm = "%s <%s>" % (name, frm)
+ e = MIMEText(body, subtype)
+ e['Subject'] = subject
+ e['From'] = frm
+ e['To'] = to
+ e.add_header('Date', formatdate())
+
+ server.sendmail(frm, to, e.as_string())
+
+ except Exception as e:
+ print("error")
+ print(e)
+