From 3f571798bf0ad37e86e7c4925a4c19c77291eed7 Mon Sep 17 00:00:00 2001 From: Logan Lipke Date: Tue, 12 May 2020 11:50:27 -0700 Subject: [PATCH] utility for quickly sending emails with python --- emailHelper.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 emailHelper.py diff --git a/emailHelper.py b/emailHelper.py new file mode 100755 index 00000000..21d09013 --- /dev/null +++ b/emailHelper.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +import smtplib +from email.message import EmailMessage +import sys + +def writeEmail(emailBody): + msg = EmailMessage() + msg.set_content(emailBody) + return msg + + +def sendEmail(email, sender, recipient, subject, smtpServer='localhost'): + email['Subject'] = subject + email['From'] = sender + email['To'] = recipient + + try: + s = smtplib.SMTP(smtpServer) + s.send_message(email) + s.quit() + return True + except exception: + print("Send Failed, {}".format(exception)) + sys.exit(2) + + + + + +#body = "Hello This Is A Test" +#subject = "Test Email" +#recipient = "logan.lipke@candelatech.com" +#sender = "lanforge@candelatech.com" + +#email = writeEmail(body) + +#sendEmail(email, sender, recipient, subject)