python outlook download attachment

import win32com.client #pip install pypiwin32 to work with windows operating sysytm
import datetime
import os

# To get today's date in 'day-month-year' format(01-12-2017).
dateToday=datetime.datetime.today()
FormatedDate=('{:02d}'.format(dateToday.day)+'-'+'{:02d}'.format(dateToday.month)+'-'+'{:04d}'.format(dateToday.year))

# Creating an object for the outlook application.
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
# Creating an object to access Inbox of the outlook.
inbox=outlook.GetDefaultFolder(6)
# Creating an object to access items inside the inbox of outlook.
messages=inbox.Items

def save_attachments(subject,which_item,file_name):
    # To iterate through inbox emails using inbox.Items object.
    for message in messages:
        if (message.Subject == subject):
            body_content = message.body
            # Creating an object for the message.Attachments.
            attachment = message.Attachments
            # To check which item is selected among the attacments.
            print (message.Attachments.Item(which_item))
            # To iterate through email items using message.Attachments object.
            for attachment in message.Attachments:
                # To save the perticular attachment at the desired location in your hard disk.
                attachment.SaveAsFile(os.path.join("D:\Script\Monitoring",file_name))
                break

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
download attachments from outlook python download outlook email attachments using python python outlook save attachment python download email attachment outlook python send email with attachment outlook 365 python outlook attachment outlook attachment download with python code how to download outlook attachment from python script get attachment from outlook email python open attachments in outlook with python outlook download attachments python python outlook add attachment python outlook download attachment python read outlook email attachment download attachment from outlook with python smtp reading attachments in outlook python outlook attach python file download file from outlook python how read outlook email attachment python How to download email attachments from outlook using python download email attachment from company outlook usining python download an email attachment from outlook usining python how to email a python attachment on outlook python download attachment from outlook python 365 outlook download attachment python automatically download file from outlook mail python script to download a file from outlook mail python script to download a file from outlook mails outlook run python script on attachment outlook run python sript on attachment download email attachments using python download outlook attachment python how to download an attachment from outlook how read attachment inside outlook with python python download outlook email attachment python3 extract outlook attachments Download attachments from outlook mail using Python python extract email attachment from outlook python extract email attachment from outlook or gmail how to download files from outlook via python python code to download attachment from outlook
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source