I am trying to access a link from an outlook mail based on the subject "Progress Dashboard". There are multiple links in the body of the mail but I need the one with the name "Instance_List" and save them as a data frame.
example link:
(https://s3.data.com/abc-data-inventory/ABCCloud/2019_09_11/ABCCloud_Asia_Instance_List_2019_09_11.csv)
My final output should be a data frame from the above link
Tried various codes, sometimes ended up with an error "No module named 'imapclient'" or just able to read the subject of the mail.
Attached the below sample code reference.
import win32com.client
import os
from datetime import datetime, timedelta
from imapclient import IMAPClient
import mailparser
outlook = win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6).Folders.Item("Inbox")
messages = inbox.Items
messages?=?messages.Restrict("[Subject]?=?'Sample Report'")
outputDir = r"C:CSV_File"
for message in messages:
if message.subject == 'Progress Dashboard'
try:
for message in list(messages):
try:
s = message.sender
for links in message.body:
links.SaveASFile(os.path.join(outputDir, attachment.FileName))
print(f"links {file_name} from {s} saved")
except Exception as e:
print("error when reading the link:" + str(e))
except Exception as e:
print("error when processing emails messages:" + str(e))
question from:
https://stackoverflow.com/questions/65914173/how-to-access-and-save-the-link-present-in-the-body-of-outlook-mail-using-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…