Tuesday, 31 October 2017

Sending email with python

  • sending email with python, first we need to install module called smtplib
  • in latest versions of python smtplib module is builtin



import smtplib
host="smtp.gmail.com"
port=587
username="abc@gmail.com"
password="*********"
from_email=username
to_list=["xyz@gmail.com","abc@gmail.com"]
email_conn=smtplib.SMTP(host,port)
email_conn.ehlo()
email_conn.starttls()
email_conn.login(username,password)
email_conn.sendmail(from_email,to_list,
                    "hello,good morning")
print("mail successfully send")
email_conn.quit()

No comments:

Post a Comment