Skip to content

Instantly share code, notes, and snippets.

@duesee
Created October 18, 2020 16:17
Show Gist options
  • Save duesee/1fcfec6650bb2c4b55b2d85bb25f708c to your computer and use it in GitHub Desktop.
Save duesee/1fcfec6650bb2c4b55b2d85bb25f708c to your computer and use it in GitHub Desktop.
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