Skip to content

Instantly share code, notes, and snippets.

@jmlon
Created August 18, 2022 12:01
Show Gist options
  • Save jmlon/f8715f24066eb62101bb658e90211b02 to your computer and use it in GitHub Desktop.
Save jmlon/f8715f24066eb62101bb658e90211b02 to your computer and use it in GitHub Desktop.
import smtplib
import argparse
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# from email.header import Header
from configparser import ConfigParser
SERVER="email-smtp.us-east-1.amazonaws.com"
PORT=587
USERNAME="YOUR_USERNAME"
PASSWORD="YOUR_PASSWORD"
FROM="[email protected]"
TO="[email protected]"
SUBJECT="THE SUBJECT GOES HERE"
BODY = """
This is a test.
"""
if __name__=="__main__":
# Build a multipart message
msg = MIMEMultipart('alternative')
msg['Subject'] = SUBJECT
msg['From'] = FROM
msg['To'] = TO
text = MIMEText(BODY, 'plain')
msg.attach(text)
html = MIMEText('<html><body><pre>'+BODY+'</pre></body></html>', 'html')
msg.attach(html)
# Deliver the message
server = smtplib.SMTP(SERVER, PORT)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login(USERNAME, PASSWORD)
server.sendmail(FROM, TO, msg.as_string())
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment