I need to download incoming attachment without past attachment from mail using Python Script.
For example:If anyone send mail at this time(now) then just download th
The below code helps by downloading the attachments from outlook emails that are
Just pass the 'Subject' argument.
import datetime
import os
import win32com.client
path = os.path.expanduser("~/Desktop/Attachments")
today = datetime.date.today()
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
def saveattachemnts(subject):
for message in messages:
if message.Subject == subject and message.Unread or message.Senton.date() == today:
# body_content = message.body
attachments = message.Attachments
attachment = attachments.Item(1)
for attachment in message.Attachments:
attachment.SaveAsFile(os.path.join(path, str(attachment)))
if message.Subject == subject and message.Unread:
message.Unread = False
break