how read outlook email attachment python code example
Example 1: send outlook email python
from mailer import Mailer
mail = Mailer(email='[email protected]', password='your_password')
mail.settings(provider=mail.MICROSOFT)
mail.send(receiver='[email protected]', subject='TEST', message='From Python!')
Example 2: 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