Want fresh tech tips in your inbox?

How to send email with Python, smtplib and Postmark

       

Here is a quick code snippet showing how to send email via SMTP with Postmark without any dependencies. It assumes you are using Heroku and have added the addon. But if not just make sure your api keys are set as environment vars.

from os import environ as env
from email.mime.text import MIMEText
import smtplib

msg = MIMEText("Message body")
msg['To'] = "somone@example.com"
msg['Bcc'] = "anotherone@example.com"
msg['From'] ="fromme@example.com"
msg['Subject'] = "Subject line"
server = smtplib.SMTP('smtp.postmarkapp.com', 587)
server.starttls()
server.login(env.get('POSTMARK_API_KEY', '...'), env.get('POSTMARK_API_KEY', '...'))
server.sendmail(msg['From'], ["somone@example.com", "anotherone@example.com"], msg.as_string())
server.quit()
Tagged w/ #python #email #sendmail #postmark #smtp

Apps I've Built

PhotoLocationChanger
Easily change the location on your photos and videos
Click here for more info about the app
PhotoDateChanger
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app