import imaplib # ========================================== # 1. CONFIGURATION # ========================================== EMAIL_ADDRESS = "marti@agile611.com" # āš ļø Insert your generated App Password here (no spaces) PASSWORD = "fcztyfdwpfrgqjgl" # Replace with your actual App Password IMAP_SERVER = "outlook.office365.com" IMAP_PORT = 993 def test_app_password_login(): print(f"šŸ”Œ Connecting to {IMAP_SERVER} on port {IMAP_PORT}...") try: # Connect to the server using SSL/TLS encryption mail = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT) # Attempt plaintext login using the App Password print("šŸ” Attempting login with App Password...") mail.login(EMAIL_ADDRESS, PASSWORD) print("āœ… Success! The App Password worked perfectly.") # Select the inbox to verify we can read data status, messages = mail.select("INBOX") if status == "OK": message_count = messages[0].decode('utf-8') print(f"šŸ“„ INBOX selected successfully. Total messages: {message_count}") # Safely log out mail.logout() print("šŸ‘‹ Logged out successfully.") except imaplib.IMAP4.error as e: print("\nāŒ Login failed!") print(f"Error details: {e}") print("\nāš ļø Note: If you see 'BasicAuthBlocked' again, your organization's global Azure settings have completely disabled basic authentication, overriding the App Password.") if __name__ == "__main__": test_app_password_login()