Skip to content

Instantly share code, notes, and snippets.

@selivan selivan/smtp_test.py
Last active Sep 1, 2018

Embed
What would you like to do?
Simple smtp send script with python smtplib. Supports TLS.
#!/usr/bin/env python3
import sys
import os
import smtplib
from email.mime.text import MIMEText
mail_from = 'send@example.com'
mail_to = ['recieve@example.com']
# AWS SES test simulator:
# https://docs.aws.amazon.com/ses/latest/DeveloperGuide/mailbox-simulator.html
#mail_to = ['success@simulator.amazonses.com']
#mail_to = ['bounce@simulator.amazonses.com']
#mail_to = ['ooto@simulator.amazonses.com']
#mail_to = ['complaint@simulator.amazonses.com']
#mail_to = ['suppressionlist@simulator.amazonses.com']
#mail_host = 'email-smtp.eu-west-1.amazonaws.com'
mail_host = 'email-smtp.us-east-1.amazonaws.com'
mail_port = 465
user = 'XXXXXXXXXX'
password = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
msg = 'Hello! Does it work?'
subj = 'smtp send test'
if __name__ == "__main__":
message = MIMEText(msg, 'plain')
message['Subject'] = subj
message['From'] = mail_from
print("Message:")
print(message.as_string())
print("Trying to send...")
conn = smtplib.SMTP_SSL(host=mail_host, port=mail_port)
conn.login(user=user, password=password)
conn.send_message(from_addr=mail_from, to_addrs=mail_to, msg=message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.