简介
我想创建某种归档脚本,它会收集所有Outlook(unicode)电子邮件的日期,发件人(姓名+地址),收件人(姓名+地址) (es)),主题并将它们放在CSV文件中。
(额外的超级解决方案是,如果它可以提取包含文件夹的名称和可能的类别 - 虽然它不是必须的。 作为最后一步,我想让它变得可移植,所以其他人可以在没有Python的情况下使用它。)
(我使用的是Python 2.7和Outlook 2013)
代码
这是我到目前为止所拥有的:
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()
问题:
如果您对任何问题有任何提示,我们将不胜感激。 在此先感谢!!
答案 0 :(得分:0)
问题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: 我没有答案。遗憾