使用Python读取outlook和写入excel

2024-09-30 14:15:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要阅读所有的电子邮件从一个特定的地址和获得“一些内容”到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

Tags: importalphaclient内容messageis电子邮件this

热门问题