DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Send An Email From Python

  • submit to reddit
        // description of your code here
Not sure where I got this from, but it does its job. Sends a simple smtp email message in python.
import smtplib
def mail(serverURL=None, sender='', to='', subject='', text=''):
    mail('', '', '', 'test', 'This is a test')
    headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (sender, to, subject)
    message = headers + text
    mailServer = smtplib.SMTP(serverURL)
    mailServer.sendmail(sender, to, message)