简体   繁体   中英

Data extraction from outlook .csv attachments using Python

I have a .csv attachment that is emailed to me daily. I'd like to read in this email using python and perform some modifications on it. The emails are sent to my Outlook email account.

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.

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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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