阅读来自Outlook的所有电子邮件 [英] Read all emails from outlook
本文介绍了阅读来自Outlook的所有电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查如何从python中的Outlook中读取所有电子邮件
I wanted to check how can I read all emails from outlook in python
我正在使用以下代码,但是此代码仅读取第一封邮件
I am using below code, but this code is reading only first mail,
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # "6" refers to the index of a folder - in this case,
# the inbox. You can change that number to reference
# any other folder
messages = inbox.Items
message = messages.GetLast()
body_content = message.Body
subject = message.Subject
categories = message.Categories
print(body_content)
print(subject)
print(categories)
我试图找到一种方法,使我们可以阅读所有电子邮件,但无法获得解决方案,因为有人知道我们如何阅读所有电子邮件并将其存储在数据库中.
I tried to find a way so that we can read all emails but unable to get a solution, is anyone know how we can read all emails and store in the database.
推荐答案
您可以遍历messages对象以获取所有电子邮件内容.
You can iterate through the messages object to get all email content.
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
'''message = messages.GetLast()
body_content = message.Body
subject = message.Subject
categories = message.Categories
print(body_content)
print(subject)
print(categories)'''
for message in messages:
print(message.Subject)
这篇关于阅读来自Outlook的所有电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文