script to get bank alert emails
This commit is contained in:
commit
59eba8d7a8
50
get.py
Normal file
50
get.py
Normal file
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user