Created
August 8, 2018 18:20
-
-
Save bcjarrett/c8cd068d0490aead9af9c2189714a01f to your computer and use it in GitHub Desktop.
Revisions
-
bcjarrett created this gist
Aug 8, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ import sys from email.mime.text import MIMEText from smtplib import SMTP_SSL, SMTPException import logging def admin_email(recipients, subject, content): smtp_server = '' sender = '' username = sender password = '' text_subtype = 'html' try: msg = MIMEText(content, text_subtype) msg['Subject'] = subject msg['From'] = sender for i in recipients: if not i: recipients.remove(i) if recipients != [None]: msg['To'] = ', '.join(recipients) else: recipients = [] conn = SMTP_SSL(smtp_server) conn.set_debuglevel(False) conn.login(username, password) try: conn.sendmail(sender, recipients + [''], msg.as_string()) finally: conn.close() except SMTPException: e = sys.exc_info()[0] # Log (e) logging.error(e)