Archives par mot-clé : Python

Récupération des mails en Python

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import smtplib
import imaplib
import email

FROM_EMAIL  = 'test@adada.fr'
FROM_PWD    = '@5d4z54dzkfùs!s'
SMTP_SERVER = 'mail.adada.fr'
SMTP_PORT   = 993

mail = imaplib.IMAP4_SSL(SMTP_SERVER,SMTP_PORT)
mail.login(FROM_EMAIL,FROM_PWD)
mail.select("INBOX")

result, data = mail.search(None, "ALL")
ids = data[0]
id_list = ids.split()
latest_email_id = id_list[-1]
result, data = mail.fetch(latest_email_id, "(RFC822)")
raw_email = data[0][1]
#print(raw_email)