Python 提取所有Outlook电子邮件';日期、发件人、收件人,以CSV为准
简介 我想创建某种存档脚本,它将收集所有Outlook(unicode)电子邮件的日期、发件人(姓名+地址)、收件人(姓名+地址)、主题,并将它们放入CSV文件中 (额外的超级解决方案是,如果它能够提取包含文件夹的名称和可能的类别,尽管这不是必须的。 作为最后一步,我想让它具有可移植性,这样其他人就可以在没有Python的情况下使用它。) (我正在使用Python 2.7和Outlook 2013) 代码 以下是我目前掌握的情况:Python 提取所有Outlook电子邮件';日期、发件人、收件人,以CSV为准,python,email,outlook,win32com,archiving,Python,Email,Outlook,Win32com,Archiving,简介 我想创建某种存档脚本,它将收集所有Outlook(unicode)电子邮件的日期、发件人(姓名+地址)、收件人(姓名+地址)、主题,并将它们放入CSV文件中 (额外的超级解决方案是,如果它能够提取包含文件夹的名称和可能的类别,尽管这不是必须的。 作为最后一步,我想让它具有可移植性,这样其他人就可以在没有Python的情况下使用它。) (我正在使用Python 2.7和Outlook 2013) 代码 以下是我目前掌握的情况: import win32com.client import sy
import win32com.client
import sys
import unicodecsv as csv
output_file = open('./outlook_farming_001.csv','wb')
output_writer = csv.writer(output_file, delimiter = ";", encoding='latin2')
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.
messages = inbox.Items
for i, message in enumerate(messages): # enumerated the items
try:
sender = message.SenderName
sender_address = message.sender.address
sent_to = message.To
date = message.LastModificationTime
subject = message.subject
output_writer.writerow([
date,
sender,
sender_address,
sent_to,
subject])
except Exception as e:
()
output_file.close()
问题:
inbox = outlook.GetDefaultFolder(6)
代码中的“6”表示收件箱
for folder in outlook.Folders:
print(folder.Name)
使用上面的for循环查找邮箱中的所有文件夹
关于问题3:
要获取发件人电子邮件ID,您可以使用以下代码:
messages = inbox.Items
message = messages.GetFirst()
sender_emailid =message.SenderEmailAddress
关于问题1:
我没有答案。对不起,问题2:
inbox = outlook.GetDefaultFolder(6)
代码中的“6”表示收件箱
for folder in outlook.Folders:
print(folder.Name)
使用上面的for循环查找邮箱中的所有文件夹
关于问题3:
要获取发件人电子邮件ID,您可以使用以下代码:
messages = inbox.Items
message = messages.GetFirst()
sender_emailid =message.SenderEmailAddress
关于问题1:
我没有答案。对不起