我想使用Python IMAPLIB模块从收件箱中获取所有电子邮件...我该怎么做?

时间:2018-06-16 22:18:55

标签: python email imaplib

这就是我所在的地方,但我不确定从哪里开始:

(low..high-1).each do |j|

1 个答案:

答案 0 :(得分:0)

我已经在gmx下对其进行了测试并且有效,请查看https://docs.python.org/3/library/email.htmlhttps://docs.python.org/3/library/imaplib.html

import imaplib
import email
mail = imaplib.IMAP4_SSL('imap')
mail.login('username', 'password')

status, messages = mail.select('INBOX')    

if status != "OK": exit("Incorrect mail box")

for i in range(1, int(messages[0])):
    res, msg = mail.fetch(str(i), '(RFC822)')
    for response in msg:
        if isinstance(response, tuple):
            msg = email.message_from_bytes(response[1])
            print (msg["subject"])