December 16, 2009

Python - Send Email With smtplib

This is mostly just for my own reference

sending an email using Python's smtplib:

import smtplib
from email.MIMEText import MIMEText

smtp_server = ''
recipients = ['',]
sender = ''
subject = 'subject goes here'
msg_text = 'message body goes here'

msg = MIMEText(msg_text)
msg['Subject'] = subject
s = smtplib.SMTP()
s.sendmail(sender, recipients, msg.as_string())

1 comment:

Marius Gedminas said...

To make things more interesting, try to make one or more of your strings contain non-ASCII characters.

I had to jump through quite a lot of hoops to make it work, once.