Guest User

Untitled

a guest
Apr 19th, 2024
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | Source Code | 0 0
  1. from imap_tools import MailBox
  2. import re
  3.  
  4. def get_msg(email_name: str, email_password: str) -> str:
  5.     email_url = 'imap.poczta.onet.pl'
  6.     email_folder = 'INBOX'
  7.     regex= "\d{6}" # 6 is number of digits of code
  8.  
  9.     with MailBox(email_url).login(email_name, email_password, email_folder) as mailbox:
  10.         for msg in mailbox.fetch(limit=1, reverse=True):
  11.             code = re.findall(regex, msg.subject)[0]
  12.             return code
  13.  
  14. def main():
  15.     email_login = '<some_login>@onet.eu'
  16.     email_password = '<some_password>'
  17.  
  18.     print(get_msg(email_name, email_password))
  19.  
  20. if __name__ == '__main__':
  21.     main()
Advertisement
Add Comment
Please, Sign In to add comment