Files
aem_moniteurs/test_imap.py
2023-06-22 10:34:18 +02:00

31 lines
742 B
Python

import imaplib
import os
from pprint import pprint
# source : https://pymotw.com/3/imaplib/index.html
def open_connection():
# Connect to the server
connection = imaplib.IMAP4_SSL('SSL0.OVH.NET')
# Login to our account
connection.login('resultats-examens@marietton.com', '9KmKPn36a')
return connection
if __name__ == '__main__':
with open_connection() as c:
# lister les mailbox
typ, data = c.list()
print('Response code:', typ)
print('Response:')
pprint(data)
# lire INBOX
typ, data = c.select('INBOX')
typ, [msg_ids] = c.search(None, 'ALL')
print('Starting messages:', msg_ids)
# What are the current flags?
typ, response = c.fetch(msg_ids, '(FLAGS)')
print('Flags before:', response)