Skip to content

Instantly share code, notes, and snippets.

@jackblk
Created February 24, 2025 07:03
Show Gist options
  • Save jackblk/81c3af31503c39c34668668f7994a806 to your computer and use it in GitHub Desktop.
Save jackblk/81c3af31503c39c34668668f7994a806 to your computer and use it in GitHub Desktop.
Pythons script to send spoofed email to Google based mailboxes.
import datetime
import smtplib
import uuid
TEST_DOMAIN = "example.com"
# Google's SMTP inbound mail server. Use `nslookup -type=mx example.com` to find the MX record.
SMTP_SERVER = "aspmx.l.google.com" # Use an MX record from Step 1
SMTP_PORT = 25 # Google's MX servers listen on port 25
# Spoofed sender and recipient
SENDER = f"spoof@{TEST_DOMAIN}" # Spoofed email
RECIPIENT = f"reciver@{TEST_DOMAIN}"
# Raw email message
message = f"""\
From: {SENDER}
To: {RECIPIENT}
Message-ID: <{uuid.uuid4()}@{TEST_DOMAIN}>
Date: {datetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S %z")}
Subject: SPF/DKIM/DMARC Test
This is a spoofed email to test email security.
"""
print(message)
# Connect to Google's mail server
try:
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
server.sendmail(SENDER, RECIPIENT, message)
print("Test email sent. Check your Gmail inbox and headers.")
except Exception as e:
print(f"Failed to send email: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment