Skip to content

Instantly share code, notes, and snippets.

@JorianWoltjer
Created March 2, 2026 10:24
Show Gist options
  • Select an option

  • Save JorianWoltjer/e1b67f5399d7f639246b2cfb7cb6daeb to your computer and use it in GitHub Desktop.

Select an option

Save JorianWoltjer/e1b67f5399d7f639246b2cfb7cb6daeb to your computer and use it in GitHub Desktop.
Easily send a raw HTML through email to test email clients
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
GMAIL_ADDRESS = "...@gmail.com"
APP_PASSWORD = "..." # https://support.google.com/mail/answer/185833?hl=en
TO_EMAIL = "...@target.tld"
msg = MIMEMultipart("alternative")
msg["Subject"] = "Test HTML email"
msg["From"] = GMAIL_ADDRESS
msg["To"] = TO_EMAIL
html_content = """
<!DOCTYPE html>
<html>
<body>
<script>alert(origin)</script>
</body>
</html>
"""
html_part = MIMEText(html_content, "html")
msg.attach(html_part)
with smtplib.SMTP("smtp.gmail.com", 587) as server:
server.starttls()
print(server.login(GMAIL_ADDRESS, APP_PASSWORD))
print(server.send_message(msg))
print("Email sent.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment