poc_send_email.py 767 B

123456789101112131415161718192021222324252627282930313233
  1. """POC on how to send email through postfix directly
  2. TODO: need to improve email score before using this
  3. """
  4. import smtplib
  5. from email.mime.multipart import MIMEMultipart
  6. from email.mime.text import MIMEText
  7. fromaddr = "hello@u.sl.meo.ovh"
  8. toaddr = "test-7hxfo@mail-tester.com"
  9. # alternative is necessary so email client will display html version first, then use plain one as fall-back
  10. msg = MIMEMultipart("alternative")
  11. msg["From"] = fromaddr
  12. msg["To"] = toaddr
  13. msg["Subject"] = "test subject 2"
  14. msg.attach(MIMEText("test plain body", "plain"))
  15. msg.attach(
  16. MIMEText(
  17. """
  18. <html>
  19. <body>
  20. <b>Test body</b>
  21. </body>
  22. </html>""",
  23. "html",
  24. )
  25. )
  26. with smtplib.SMTP(host="localhost") as server:
  27. server.sendmail(fromaddr, toaddr, msg.as_string())