Skip to content

Instantly share code, notes, and snippets.

@mamun67
Forked from ruanbekker/python_mailer_smtplib.py
Created August 26, 2019 12:06
Show Gist options
  • Save mamun67/2e1590469b00bf4f447aaee3173fc602 to your computer and use it in GitHub Desktop.
Save mamun67/2e1590469b00bf4f447aaee3173fc602 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 = "[email protected]"
to_address = "[email protected]"
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