Skip to content

Instantly share code, notes, and snippets.

@duesee

duesee/redirect.py

Created Oct 18, 2020
Embed
What would you like to do?
Google Redirect Test
# Note "insecure login" and "IMAP" must be activated.
from getpass import getpass
username = getpass("Username: ")
password = getpass("Password: ")
# Append via IMAP
from email.message import Message
test = Message()
test.add_header("From", f"{username}")
test.add_header("To", f"{username}")
test.add_header("Subject", "Link Redirect Test (IMAP)")
test.set_payload("The original link is: https://imap.example.org")
print(test)
from imapclient import IMAPClient
imap = IMAPClient("imap.gmail.com", 993)
imap.login(username, password)
imap.append("inbox", test.as_bytes())
imap.select_folder("inbox")
fetched_test = imap.fetch("*", b"BODY[]")
print(fetched_test)
# When send via SMTP
from email.message import Message
test = Message()
test.add_header("From", f"{username}")
test.add_header("To", f"{username}")
test.add_header("Subject", "Link Redirect Test (SMTP)")
test.set_payload("The original link is: https://smtp.example.org")
print(test)
from smtplib import SMTP_SSL
smtp = SMTP_SSL("smtp.gmail.com", 465)
smtp.login(username, password)
smtp.send_message(test)
fetched_test = imap.fetch("*", b"BODY[]")
print(fetched_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment