Skip to content

Instantly share code, notes, and snippets.

@bcjarrett
Created August 8, 2018 18:20
Show Gist options
  • Select an option

  • Save bcjarrett/c8cd068d0490aead9af9c2189714a01f to your computer and use it in GitHub Desktop.

Select an option

Save bcjarrett/c8cd068d0490aead9af9c2189714a01f to your computer and use it in GitHub Desktop.

Revisions

  1. bcjarrett created this gist Aug 8, 2018.
    38 changes: 38 additions & 0 deletions simple_email.py
    Original 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)