Python: Send Email

By Xah Lee. Date:

Here's a python script to send email.

# -*- coding: utf-8 -*-
# python 2

import smtplib

smtpServer='smtp.example.com';
fromAddr='boss@example.com';
toAddr='joe@example.com';
text='''Subject: newfound love

Hi friend,

long time no write, i have a new manifesto i
 think it would be of interest for you to peruse.
'''

server = smtplib.SMTP(smtpServer)
server.set_debuglevel(1)
server.sendmail(fromAddr, toAddr, text)
server.quit()

Note: the set_debuglevel() is nice because you see all the interactions with the smtp server. Useful when you want to see what's going on with a smtp server.

Python

Regex

Text Processing

Web

Misc