Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created July 26, 2017 15:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save ruanbekker/a0a119faee3f7493262a8c937ae0c33f to your computer and use it in GitHub Desktop.
Save ruanbekker/a0a119faee3f7493262a8c937ae0c33f to your computer and use it in GitHub Desktop.
Python SMTP Mailer using Amazon SES (smtplib)
import sys
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
name = "Ruan"
from_address = "no-reply@mydomain.com"
to_address = "ruan@mydomain.com"
subject = "Test"
msg = MIMEMultipart()
msg['From'] = from_address
msg['To'] = to_address
msg['Subject'] = "Notification: {}".format(subject)
body = """
Hello, {0}.
This is a plain email.
Kind Regards,
Me
""".format(name)
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('email-smtp.eu-west-1.amazonaws.com', 587)
server.starttls()
server.login("USER", "PASS")
text = msg.as_string()
server.sendmail(from_address, to_address, text)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment