Using Python to access outlook with win32com

Category > PYTHON || Published on : Monday, February 8, 2021 || Views: 499 || Using Python to access outlook with win32com


Here Pawan Kumar will explain how to Using Python to access outlook with win32com

Run below line at command prompt

 pip install pywin32

Create a new python file with following source codes

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")

inbox = outlook.GetDefaultFolder(6)
messages = inbox.Items
messages.Sort('[ReceivedTime]', False)
message = messages.GetLast()

for attachment in message.Attachments:
    print(attachment.FileName)