首页 > 解决方案 > 使用 Python 阅读 Outlook 并写入 Excel

问题描述

我需要阅读来自特定地址的所有电子邮件并将“一些内容”放入 excel

我在阅读电子邮件方面取得了一些成功,但我坚持将这些电子邮件的内容输入到 Excel 中

import win32com.client
import xlsxwriter
import pandas
wb = xlsxwriter.Workbook('Planned_power_outage.xlsx')
ws = wb.add_worksheet()
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI").Folders
folder = outlook(1)
inbox = folder.Folders("Inbox")
messages = inbox.Items
for message in messages:
if (message.SenderEmailAddress) == 'addess here':
       sent_date = message.senton.date()
       sender = message.Sender
       subject = message.Subject
       content = message.body 
       possible_node = subject.split(" ")[1]
              print(sender,subject,content)

i expect to see the output as below in a excel file

SENDER  SUBJECT                 CONTENT
alpha   this is subject0    blahbalahblahablah
alpha   this is subject1    blahbalahblahablah
alpha   this is subject2    blahbalahblahablah

标签: pythonoutlook

解决方案


推荐阅读