Skip to content

Instantly share code, notes, and snippets.

@bcjarrett
Created August 8, 2018 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcjarrett/c8cd068d0490aead9af9c2189714a01f to your computer and use it in GitHub Desktop.
Save bcjarrett/c8cd068d0490aead9af9c2189714a01f to your computer and use it in GitHub Desktop.
Simple Email Tool
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment