diff --git a/gmail/email_count.py b/gmail/email_count.py new file mode 100644 index 0000000..b2880d0 --- /dev/null +++ b/gmail/email_count.py @@ -0,0 +1,37 @@ +import os +import imaplib +import time +import re +from dotenv import load_dotenv + +load_dotenv() + +print(os.environ.get("APP_PASSWORD")) +################ IMAP SSL ############################## + +with imaplib.IMAP4_SSL(host="imap.gmail.com", port=imaplib.IMAP4_SSL_PORT) as imap_ssl: + print("Connection Object : {}".format(imap_ssl)) + print("Logging into mailbox...") + try: + resp_code, response = imap_ssl.login("alexander@ahosking.com", os.environ.get("APP_PASSWORD")) + except Exception as e: + print("ErrorType : {}, Error : {}".format(type(e).__name__, e)) + resp_code, response = None, None + + print("Response Code : {}".format(resp_code)) + print("Response : {}\n".format(response[0].decode())) + + imap_ssl.select('inbox') + resp_code, messages = imap_ssl.search(None, 'UnSeen') + if resp_code == 'OK': + if len(messages[0].split()) > 0: + print('True') + print(messages[0].split()) + print(len(messages[0].split())) + else: + print('False') + +############### Logout of Mailbox ###################### + print("\nLogging Out....") + + imap_ssl.close() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cb5d4c3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +python-dotenv==0.20.0