9/09/2016

Python :: python send email gmail multiple recipients.

Python :: python send email gmail multiple recipients.
1. Create file sendmail.py
2. Insert Code
  1. #!/usr/bin/python
  2. import smtplib
  3. from smtplib import SMTP
  4.  
  5. recipients = ['suwit.jph@gmail.com', 'suwit_jph@hotmail.co.th']
  6.  
  7. def send_email (message, status):
  8.     fromaddr = 'scivalve.suwit@gmail.com'
  9.     server = SMTP('smtp.gmail.com:587')
  10.     server.ehlo()
  11.     server.starttls()
  12.     server.ehlo()
  13.     server.login('scivalve.suwit@gmail.com', 'password')
  14.     server.sendmail(fromaddr, recipients, 'Subject: %s\r\n%s' % (status, message))
  15.     server.quit()
  16.  
  17. send_email("Test","Test send mail")
  18.  
  19.  

3. Test Run Command.
  1. ./sendmail.py

Example : http://stackoverflow.com/questions/2050 ... -addresses

No comments:

Post a Comment