Sunday, October 18, 2015

send mail from python

import smtplib

def send_email(sender, receiver, subject, body):
    msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s"
        %(sender, receiver, subject, body))
    s = smtplib.SMTP('smtp.gmail.com')
    s.starttls()
    s.login('user@gmail.com','pass')
    s.sendmail(sender, [receiver], msg)
    s.quit()
   
send_email('user@gmail.com','user@gmail','Test mail from script','Regards,Parag')