From 59eba8d7a80a5419f065e0548be099922191a86a Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 15 May 2023 07:27:24 -0400 Subject: [PATCH] script to get bank alert emails --- get.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 get.py diff --git a/get.py b/get.py new file mode 100644 index 0000000..6c7d8d0 --- /dev/null +++ b/get.py @@ -0,0 +1,50 @@ +import imaplib +import email +from getpass import getpass + +# IMAP server settings for Hotmail +imap_server = 'imap-mail.outlook.com' +imap_port = 993 + +# Email credentials +email_address = input('Email address: ') +password = getpass('Password: ') + +# Connect to the IMAP server +imap_conn = imaplib.IMAP4_SSL(imap_server, imap_port) + +# Login to the email account +imap_conn.login(email_address, password) + +# Select the 'alerts' folder +imap_conn.select('Alerts') + +# Search for unseen emails in the 'alerts' folder +status, email_ids = imap_conn.search(None, 'UNSEEN') + +# Loop through the email IDs +for email_id in email_ids[0].split(): + # Fetch the email by ID + status, email_data = imap_conn.fetch(email_id, '(RFC822)') + + # Parse the email data + raw_email = email_data[0][1] + email_message = email.message_from_bytes(raw_email) + + # Extract the body of the email + if email_message.is_multipart(): + for part in email_message.get_payload(): + if part.get_content_type() == 'text/plain': + email_body = part.get_payload(decode=True).decode() + break + else: + email_body = email_message.get_payload(decode=True).decode() + + print("Email body:") + print(email_body) + print("------------------------") + +# Logout and close the connection +imap_conn.logout() +imap_conn.close() +