initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
from imap_tools import MailBox
|
||||
|
||||
# Configuration
|
||||
imap_server = os.getenv('IMAP_SERVER')
|
||||
email_account = os.getenv('EMAIL_ACCOUNT')
|
||||
password = os.getenv('EMAIL_PASSWORD')
|
||||
|
||||
# Fetch all mails of a mailbox via IMAP
|
||||
def fetch_emails() -> list[dict]:
|
||||
mailbox = MailBox(imap_server)
|
||||
mailbox.login(email_account, password)
|
||||
msgs = list()
|
||||
for msg in mailbox.fetch(mark_seen=False):
|
||||
msgs.append({
|
||||
"uid": msg.uid,
|
||||
"from": msg.from_,
|
||||
"to": ', '.join(msg.to),
|
||||
"subject": msg.subject,
|
||||
"text": msg.text,
|
||||
"date": msg.date_str
|
||||
})
|
||||
mailbox.logout()
|
||||
return msgs
|
||||
Reference in New Issue
Block a user