python automatically download file from outlook mail code example
Example: python outlook download attachment
import win32com.client
import datetime
import os
dateToday=datetime.datetime.today()
FormatedDate=('{:02d}'.format(dateToday.day)+'-'+'{:02d}'.format(dateToday.month)+'-'+'{:04d}'.format(dateToday.year))
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox=outlook.GetDefaultFolder(6)
messages=inbox.Items
def save_attachments(subject,which_item,file_name):
for message in messages:
if (message.Subject == subject):
body_content = message.body
attachment = message.Attachments
print (message.Attachments.Item(which_item))
for attachment in message.Attachments:
attachment.SaveAsFile(os.path.join("D:\Script\Monitoring",file_name))
break