Spaces:
Paused
Paused
Download Telegram_Job_Bot/imap_test.py from telegramjobupload/README: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/spaces/telegramjobupload/README/resolve/main/Telegram_Job_Bot/imap_test.py
- Command line
-
hf download hf://spaces/telegramjobupload/README/Telegram_Job_Bot/imap_test.py
-
curl -L -o imap_test.py https://huggingface.co/spaces/telegramjobupload/README/resolve/main/Telegram_Job_Bot/imap_test.py
1.33 kB
| import os | |
| import imaplib | |
| import email | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv(override=True) | |
| BOT_EMAIL = os.getenv("BOT_EMAIL") | |
| BOT_EMAIL_PASSWORD = os.getenv("BOT_EMAIL_PASSWORD") | |
| def test_email_connection(): | |
| if not BOT_EMAIL or not BOT_EMAIL_PASSWORD: | |
| print("β ERROR: BOT_EMAIL or BOT_EMAIL_PASSWORD is missing in your .env file!") | |
| return | |
| print(f"π Attempting to log into {BOT_EMAIL}...") | |
| try: | |
| # Connect to Gmail's IMAP server | |
| mail = imaplib.IMAP4_SSL("imap.gmail.com") | |
| # Login | |
| mail.login(BOT_EMAIL, BOT_EMAIL_PASSWORD) | |
| print("β SUCCESS! The bot successfully logged into the email inbox.") | |
| # Select the inbox and check how many emails there are | |
| mail.select("inbox") | |
| status, messages = mail.search(None, "ALL") | |
| email_count = len(messages[0].split()) | |
| print(f"π¬ There are {email_count} emails in the inbox.") | |
| # Logout | |
| mail.logout() | |
| except imaplib.IMAP4.error as e: | |
| print("β LOGIN FAILED. Please check if your App Password is correct.") | |
| print(f"Error Details: {e}") | |
| except Exception as e: | |
| print(f"β UNEXPECTED ERROR: {e}") | |
| if __name__ == "__main__": | |
| test_email_connection() | |