diff options
Diffstat (limited to 'email_helper.py')
-rw-r--r-- | email_helper.py | 28 |
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) + |