简体   繁体   中英

Extracting Email Attachments from Outlook 365 using Python

Has anyone tried extracting email attachments based on some text in the subject? If so how did you go about it? I'm ideally looking to save them all to a folder.

Thanks for the help!:D

Assuming you want to use Outlook Object Model to talk to the locally installed Outlook, create an instance of the Outlook.Application object, retrieve the Namespace object from Application.GetNmaespace("MAPI") , call Namespace.Logon . You can then retrieve the source folder (eg Namespace.GetDefaultFolder(olFolderInbox) ), build an appropriate query and use it to call Items.Find/FindNext or Items.Restrict ( Items comes from MAPIFolder.Items ). Once you have the matching message, loop through its attachment ( MailItem.Attachments ) and save them ( Attachment.SaveAsFile ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM