Simple Email Program in Python

This email program will send email to through the local SMTP server on your localhost.


import smtplib

mymail = "name@email.com"



def mail(serverURL=None, sender='', to='', subject='', text=''):
    """
    Usage:
    mail('somemailserver.com', 'me@example.com', 'someone@example.com', '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)
    mailServer.quit()




mail("127.0.0.1", "haveaniceflight@seeul8tr.com" , mymail,"Have a nice trip", "Try to have a nice time in New Orleans! Get us some great data.")

Comments

Popular posts from this blog

Find countries in a file's text using regular expressions and Perl

Make links active in Excel 2007