mail-demo.py 704 B

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import smtplib
  3. import imghdr
  4. from email.message import EmailMessage
  5. EMAIL_ADDRESS = os.environ.get('EMAIL_USER')
  6. EMAIL_PASSWORD = os.environ.get('EMAIL_PASS')
  7. contacts = ['YourAddress@gmail.com', 'test@example.com']
  8. msg = EmailMessage()
  9. msg['Subject'] = 'Check out Bronx as a puppy!'
  10. msg['From'] = EMAIL_ADDRESS
  11. msg['To'] = 'YourAddress@gmail.com'
  12. msg.set_content('This is a plain text email')
  13. msg.add_alternative("""\
  14. <!DOCTYPE html>
  15. <html>
  16. <body>
  17. <h1 style="color:SlateGray;">This is an HTML Email!</h1>
  18. </body>
  19. </html>
  20. """, subtype='html')
  21. with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
  22. smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
  23. smtp.send_message(msg)