Skip to content

Instantly share code, notes, and snippets.

@liyanage
Created November 18, 2012 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liyanage/4102800 to your computer and use it in GitHub Desktop.
Save liyanage/4102800 to your computer and use it in GitHub Desktop.
Python email sending example
#!/usr/bin/env python
import email.mime.text
import email.header
import smtplib
email.Charset.add_charset('utf-8', email.Charset.QP, email.Charset.QP, 'utf-8')
me = u'Foo Bar <test@example.com>'
you = me
msg = email.mime.text.MIMEText(u'<strong>test\u2192</strong>', 'html', 'UTF-8')
msg['Subject'] = email.header.Header(u'python mail test \u2192', 'UTF-8')
msg['From'] = email.header.Header(me, 'UTF-8')
msg['To'] = email.header.Header(you, 'UTF-8')
s = smtplib.SMTP('smtp.example.com')
s.sendmail(me, [you], msg.as_string())
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment