Skip to content

Instantly share code, notes, and snippets.

@jlamoree
Created February 4, 2021 22:57
Show Gist options
  • Save jlamoree/0697c88d45e1adc38b4c1ea5ff95bd50 to your computer and use it in GitHub Desktop.
Save jlamoree/0697c88d45e1adc38b4c1ea5ff95bd50 to your computer and use it in GitHub Desktop.
Send a test email using the Disposition-Notification-To header to verify whether a data leak exists.
#!/usr/bin/env python3
import smtplib
from email.message import EmailMessage
import email.utils
import ssl
server = {"hostname": "my.mailserver.tld", "port": 587}
auth = {"username": "username", "password": "password"}
sender = {"name":"The Sender", "address":"sender@domain.tld"}
recipient = {"name":"The Recipient", "address":"recipient@domain.tld"}
subject = "[TEST] A receipt test"
message = "This is a delivery notification test email."
msg = EmailMessage()
msg.set_content(message)
msg["To"] = f"\"{recipient['name']}\" <{recipient['address']}>"
msg["From"] = f"\"{sender['name']}\" <{sender['address']}>"
msg["Subject"] = subject
msg.add_header("Message-ID", email.utils.make_msgid())
msg.add_header("Content-Language", "en-us")
msg.add_header("Disposition-Notification-To", sender["address"])
sslctx = ssl.create_default_context()
smtp = smtplib.SMTP(server["hostname"], server["port"])
smtp.starttls(context=sslctx)
smtp.login(auth["username"], auth["password"])
smtp.send_message(msg)
smtp.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment