Skip to content

Instantly share code, notes, and snippets.

@ArshansGithub
Created February 4, 2024 17:55
Show Gist options
  • Select an option

  • Save ArshansGithub/a8bb4b322a738045b81610756fc4ad11 to your computer and use it in GitHub Desktop.

Select an option

Save ArshansGithub/a8bb4b322a738045b81610756fc4ad11 to your computer and use it in GitHub Desktop.
Email Verification Solver VIA IMAP
class EmailVerification:
def __init__(self, email, password):
self.server = IMAPClient('outlook.office365.com', port=993, use_uid=True)
self.server.login(email, password)
self.server.select_folder('INBOX')
def amount(self):
return self.server.select_folder('INBOX')[b'EXISTS']
def check(self, target, match, methodType="text", delete=True):
if methodType == "subject":
emails = self.server.search(['SUBJECT', target])
elif methodType == "from":
emails = self.server.search(['FROM', target])
elif methodType == "text":
emails = self.server.search(['TEXT', target])
if len(emails) == 0:
return False
for email in emails:
data = self.server.fetch(email, ["ENVELOPE", "BODY[TEXT]"])
toReturn = {}
for items in data.items():
toReturn["from"] = items[1][b'ENVELOPE'].from_[0].mailbox.decode("utf-8") + "@" + items[1][b'ENVELOPE'].from_[0].host.decode("utf-8")
toReturn["to"] = items[1][b'ENVELOPE'].to[0].mailbox.decode("utf-8") + "@" + items[1][b'ENVELOPE'].to[0].host.decode("utf-8")
toReturn["subject"] = items[1][b'ENVELOPE'].subject.decode("utf-8")
toReturn["body"] = items[1][b'BODY[TEXT]'].decode("utf-8").strip()
if toReturn["to"] == match:
if delete:
self.server.delete_messages(email)
return toReturn
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment