Created
March 9, 2021 15:42
-
-
Save tuck1s/6de2cf9377d6d04a27b7b9803584042e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import imaplib, os | |
# Very simple IMAP client - prints messages in inbox | |
imap_host = os.getenv('IMAP_HOST') | |
imap_user = os.getenv('IMAP_USER') | |
imap_pass = os.getenv('IMAP_PASSWORD') | |
# connect to host using SSL | |
imap = imaplib.IMAP4_SSL(imap_host) | |
## login to server | |
imap.login(imap_user, imap_pass) | |
imap.select('Inbox') | |
print('Reading messages from {} for user {}'.format(imap_host, imap_user)) | |
tmp, data = imap.search(None, 'ALL') | |
for num in data[0].split(): | |
tmp, data = imap.fetch(num, '(RFC822)') | |
if tmp == 'OK': | |
id = ' Message {0} '.format(num.decode('utf-8)')) | |
sep = '=' | |
print(sep * 10 + id + sep *(100-len(id))) | |
message = data[0][1].decode('utf-8') | |
print(message) | |
else: | |
print(tmp) | |
imap.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set up the environment variables before running.