html_email_ssl.py 783 B

12345678910111213141516171819202122232425262728293031323334
  1. import smtplib
  2. from email.message import EmailMessage
  3. from email.utils import make_msgid
  4. msg = EmailMessage()
  5. asparagus_cid = make_msgid()
  6. msg.add_alternative("""\
  7. <html>
  8. <head></head>
  9. <body>
  10. <p>Hello</p>
  11. <p>Here is an example of sending HTML email using Python. Please click on below link:
  12. <a href="https://www.roytuts.com/how-to-send-an-html-email-using-python/">
  13. Send an HTML email using Python
  14. </a>
  15. </p>
  16. </body>
  17. </html>
  18. """.format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
  19. fromEmail = 'gmail@gmail.com'
  20. toEmail = 'gmail@gmail.com'
  21. msg['Subject'] = 'HTML Message'
  22. msg['From'] = fromEmail
  23. msg['To'] = toEmail
  24. s = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  25. s.login(fromEmail, 'gmail password')
  26. s.send_message(msg)
  27. s.quit()