It is actually pretty easy to send emails with python. The smtplib module provides the necessary "tools" to send mail to any Internet machine with an SMTP or ESMTP listener daemon. In this script I am using gmail, but it is not limited to Google as long as your provide the correct smtp server + port. Python 2.7.3 from email .mime.text import MIMEText import smtplib def sendmail(to,subject,text): user = 'name@gmail.com' pwd = 'password' msg = MIMEText(text) msg['From'] = 'james@gmail.com' msg['To'] = to msg['Subject'] = subject try : smtpServer = smtplib .SMTP('smtp.gmail.com', 587) smtpServer.ehlo() smtpServer.starttls() smtpServer.ehlo() smtpServer.login( user , pwd ) smtpServer.sendmail( user , to, msg.as_string()) smtpServer. close () print
A blog about Linux, Debian, Ubuntu, Raspberry Pi and Python.