How to download Outlook (Office 365) Emails as .EML or .MSG Files

Introduction

Outlook Mail (Office 365) In this article, you will learn how to download Outlook (Office 365) emails as .EML or .MSG files using ZappySys SSIS PowerPack without writing any code. We’ll leverage the power of Microsoft Graph API, which provides unified access to Microsoft 365 services like Outlook Mail, and integrate it seamlessly using the API Connector for SSIS Outlook Mail (Office 365), Web API Destination and other components. By the end, you’ll be able to automate the process of extracting emails and saving them to disk in standard email formats directly from your SSIS package.

Prerequisites

Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:
  1. SSIS designer installed. Sometimes it is referred to as BIDS or SSDT (download it from the Microsoft site).
  2. Basic knowledge of SSIS package development using Microsoft SQL Server Integration Services.
  3. Make sure ZappySys SSIS PowerPack is installed (download it, if you haven't already).
  4. (Optional step). Read this article, if you are planning to deploy packages to a server and schedule their execution later.

Step 1: Register an Application in Azure Portal

To access Outlook emails via Microsoft Graph API, the first step is to register an application in the Azure Portal. This allows your SSIS package to authenticate securely and retrieve mail data from Office 365.
Step by step info is available here Outlook Mail (Office 365) Connector Authentication section.

User Credentials

Use delegated access (User Credentials) whenever you want to let a signed-in user work with their own resources or resources they can access. Whether it’s an admin setting up policies for their entire organization or a user deleting an email in their inbox, all scenarios involving user actions should use delegated access.
Refer to this links for the detailed steps: User Credentials [OAuth]

Application Credentials

Application-only access is broader and more powerful than delegated access (User Credentials), so you should only use app-only access where needed. Use it when:

  1. The application needs to run in an automated way, without user input (for example, a daily script that checks emails from certain contacts and sends automated responses).
  2. The application needs to access resources belonging to multiple different users (for example, a backup or data loss prevention app might need to retrieve messages from many different chat channels, each with different participants).
  3. You find yourself tempted to store credentials locally and allow the app to sign in ‘as’ the user or admin.

Refer to this links for the detailed steps: Application Credentials [OAuth]

Step 2: Download Outlook (Office 365) Emails as .EML Files using SSIS

Now let’s look at some examples of how to access your Outlook emails using our easy-to-use Outlook Mail Connector in ZappySys SSIS PowerPack. This connector simplifies calling the Microsoft Graph API, so you can retrieve emails with just a few clicks.
In this section we will learn how to configure and use Outlook Mail (Office 365) Connector in API Source to extract data from Outlook Mail (Office 365).

  1. Begin with opening Visual Studio and Create a New Project.
  2. Select Integration Service Project and in new project window set the appropriate name and location for project.
    And click OK.
  3. In the new SSIS project screen you will find the following:
    1. SSIS ToolBox on left side bar
    2. Solution Explorer and Property Window on right bar
    3. Control flow, data flow, event Handlers, Package Explorer in tab windows
    4. Connection Manager Window in the bottom

    SSIS Project Screen

    Note: If you don’t see ZappySys SSIS PowerPack Task or Components in SSIS Toolbox, please refer to this help link.
  4. Now, Drag and Drop SSIS Data Flow Task from SSIS Toolbox. Double click on the Data Flow Task to see Data Flow designer.

    SSIS Data Flow Task - Drag and Drop

  5. From the SSIS toolbox drag and API Source (Predefined Templates) on the data flow designer surface, and double click on it to edit it:
    SSIS API Source (Predefined Templates) - Drag and Drop
  6. Select New Connection to create a new connection:
    API Source - New Connection
  7. Use a preinstalled Outlook Mail (Office 365) Connector from Popular Connector List or press Search Online radio button to download Outlook Mail (Office 365) Connector. Once downloaded simply use it in the configuration:
    Outlook Mail (Office 365) Connector Selection

    Outlook Mail (Office 365) Connector Selection

  8. Proceed with selecting the desired Authentication Type. Then select API Base URL (in most cases default one is the right one). Finally, fill in all the required parameters and set optional parameters if needed. You may press a link Steps to Configure which will help set certain parameters. More info is available in Authentication section.
    1. User Credentials [OAuth]
      User Credentials [OAuth]

      User Credentials [OAuth]

      OR

    2. Application Credentials [OAuth]
      Application Credentials [OAuth]

      Application Credentials [OAuth]

  9. Select the Get Messsages endpoint, change/pass the properties values, and click on Preview Data button to make the API call.
    API Source - Get Messages Endpoint

    API Source – Get Messages Endpoint

  10. That’s it — click OK and you’re done! In just a few clicks, you’ve successfully configured a connection to Outlook Mail (Office 365) using the Outlook Mail Connector.
  11. Now let’s move to the next step — retrieving the full email content.
    You’ll use the Web API Destination component to make the Get MIME content API call. Within this task, you can dynamically pass the Message ID to fetch each email’s raw .EML content from Outlook (Office 365).
    For more details, refer to the official Microsoft documentation: Get Outlook Mail MIME content
  12. Drag and drop the Web API Destination component from the SSIS Toolbox onto your Data Flow.
    Double-click to open it, then configure as follows and create a new OAuth Connection if needed:

    URL:

    https://graph.microsoft.com/v1.0/me/messages/<%Id%>/$value

    The placeholder is dynamically replaced by SSIS at runtime with the actual Message ID, allowing the Web API Destination to download each email’s .EML content individually.

    Get MIME content’ API call using the Web API Destination

    Get MIME content’ API call using the Web API Destination

  13. You’ll also need to create the OAuth connection using the same credentials.
    On the Advanced tab, make sure to set the Redirect URL correctly.

    For detailed steps, refer to this guide:
    How to set up OAuth 2.0 in SSIS

    Outlook Mail OAuth 2.0 Connection

    Outlook Mail OAuth 2.0 Connection

  14. Next, add a Derived Column transformation to create a new column that defines the file path for saving the .EML file.
    In this example, we’ll use the Message ID to generate a unique file name for each email:

    Expression:

    (DT_WSTR,1000)”E:\\zsTemp\\” + [Id] + “.eml”

    Derived Column - Dynamic File Path

    Derived Column – Dynamic File Path

  15. Now, add an Export Column transformation to save the email content to a file.
    • Extract Column: set to ResponseText (this holds the email content from Web API Destination)
    • File Path Column: set to the column you created in the Derived Column step (e.g., FilePath)
    • Enable Force Truncate and Write Byte-Order Mark options
    Export Column - write the email content to a file on disk.

    Export Column – write the email content to a file on disk.

  16. Set File Encoding to UTF-8 (Optional)
    Next, go to the Control Flow and use the Advanced File System Task to convert the downloaded .eml file’s encoding to UTF-8.
    This step is optional — I had to apply it on my system because the files weren’t opening correctly due to a non-UTF-8 encoding.
    If you encounter a similar issue, follow this step to ensure proper compatibility with email clients.
    Advanced File System Task - Change Encoding

    Advanced File System Task – Change Encoding

  17. That’s it! The process will now automatically download your Outlook messages to your local system as .EML files.
    Outlook .eml file’s

    Outlook .eml file’s

Conclusion

Using ZappySys SSIS PowerPack and Microsoft Graph API, you can easily automate the download of Outlook (Office 365) emails in .EML format — all within SSIS and without writing any code.
This approach is ideal for archiving, compliance, or integrating email content into downstream systems.
With a few simple components and steps, your email extraction workflow can be up and running in minutes.

Posted in REST API, REST API Integration, REST Connector, SSIS OAuth Connection, SSIS PowerPack, SSIS WEB API Destination, Uncategorized.