我想使用Python IMAPLIB模块从收件箱中提取所有电子邮件...我该怎么做? [英] I want to grab all emails from an inbox using the Python IMAPLIB module... how can I do this?
本文介绍了我想使用Python IMAPLIB模块从收件箱中提取所有电子邮件...我该怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的位置,但我不确定从这里去哪里:
This is where I am at, but I'm not sure where to go from here:
import imaplib
import email
conn = imaplib.IMAP4()
conn.login("username", "password")
status, messages = conn.select('INBOX')
if status != "OK":
print ("Incorrect mail box")
exit()
print (messages)
推荐答案
我已经在gmx下对其进行了测试,并且可以正常工作,请查看 https://docs.python.org/3/library/email.html 和 https://docs.python.org/3/library/imaplib.html
I have test it under gmx and it works, please take a look at https://docs.python.org/3/library/email.html and https://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"])
这篇关于我想使用Python IMAPLIB模块从收件箱中提取所有电子邮件...我该怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文