Sunday, April 05, 2009

Using the smtplib to send emails from python / django


import smtplib
addr_from = 'xyz@gmail.com' # this will be your address
addr_to = 'abc@yahoo.com' # person whom you want to send the email
server = smtplib.SMTP('smtp.gmail.com') # if you are using gmail then your smtp server is smtp.gmail.com
msg = ('From:'+addr_from+'\r\n'+'To:'+addr_to+'\r\n\r\n')
msg = msg + 'Testing SMTPLIB' #test message
server.ehlo() # Optional step
server.starttls()
server.ehlo() #Optional step
server.login('xyz@gmail.com','password')
server.sendmail(addr_from,addr_to,msg))

Thats it ... and python takes care of sending the email.

0 comments: