简体   繁体   English

使用 Python 从 Outlook .csv 附件中提取数据

[英]Data extraction from outlook .csv attachments using Python

I have a .csv attachment that is emailed to me daily.我有一个每天通过电子邮件发送给我的 .csv 附件。 I'd like to read in this email using python and perform some modifications on it.我想使用 python 阅读这封电子邮件并对其进行一些修改。 The emails are sent to my Outlook email account.电子邮件将发送到我的 Outlook 电子邮件帐户。

This is what I am doing:这就是我正在做的:

import win32com.client

my_outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

folder = outlook.GetDefaultFolder(6) #index 
for item in folder.Items
print(item.body)

However, this is for extracting data within the email, how would I read the actual attachment that is being sent?但是,这是为了提取电子邮件中的数据,我将如何阅读正在发送的实际附件? I am looking into extract-msg PyPi as well.我也在研究extract-msg PyPi。

Any insight will be helpful.任何见解都会有所帮助。

To read the attachment, use the following..要阅读附件,请使用以下..

import win32com.client
import datetime
import os
import email
outlook = win32com.client.Dispatch("outloook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # change depending on folder you wish to see
message = inbox.items

for message in inbox.Items:
      if message.Unread == True # finds unread mesages
      for attachment in message.Attachments:
      

This will show you all unread email attachments, simply complete the code with the file address you wish to save the attachments..这将向您显示所有未读的电子邮件附件,只需使用您希望保存附件的文件地址完成代码即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM