Friday, June 22, 2012

Sending Email using Python and SMTP

This is a simple python script which uses Gmail SMTP or any smtp you want to send mails using Python

First of all install module mailer :-

easy_install mailer

Here we go:-
import mailer
import traceback
        try:
                message = mailer.Message()
                message.From = "from@example.com"
                message.To = "to@example.com"
                message.Subject = "This is the Mail Title"
                message.Body = "This is the Mail body"
                mailer = mailer.Mailer('smtp.gmail.com')
                mailer.login("emailID","PASSWORD")
                mailer.use_tls=True
                mailer.send(message)
        except:
                traceback.print_exc()

This script will send mail using python and Smtp server.

 You can also send HTML mails so you have to use:-

message.HTML='''HTML DATA''' 
 

No comments:

Post a Comment