text_email_headers.py 446 B

12345678910111213141516171819
  1. import smtplib
  2. from email.parser import BytesParser, Parser
  3. from email.policy import default
  4. headers = Parser(policy=default).parsestr(
  5. 'From: Foo Bar <gmail@gmail.com>\n'
  6. 'To: <gmail@gmail.com>\n'
  7. 'Subject: Simple Text Message\n'
  8. '\n'
  9. 'Email sending example using Python. It\'s Simple Text Message\n')
  10. s = smtplib.SMTP('smtp.gmail.com', 587)
  11. s.starttls()
  12. s.login('gmail@gmail.com', 'gmail\'s password')
  13. s.send_message(headers)
  14. s.quit()