Send email – python

#!/usr/bin/env python
#
# An example of how to send a quick email
#

import smtplib

smtpServer = 'smtp.example.com'
recipients = ['jem@example.com']
sender     = 'someone@example.com'
fromText   = 'Jan Erik Moström '
toText     = 'Jan Erik Moström '
subject    = 'A test mail'

head = "To: %s\nFrom: %s\nSubject: %s\n\n" % (toText,fromText, subject )

msg  = """This is quick
test mail just to make
sure that everything
works"""



email  = smtplib.SMTP( smtpServer )
result = email.sendmail( sender, recipients, head + msg )

if result:
    for toWho in result.keys():
        print 'Error in sending to : %s' % toWho

Comments are closed.

blog comments powered by Disqus