Download Outlook Email Attachments Using Microsoft Graph Api In C# [2021] May 2026

Here is how to iterate through attachments and save them to your local disk:

The Microsoft Graph API provides a unified, powerful way to manage Outlook data. By leveraging the .Attachments collection and the FileAttachment class, you can easily automate your document workflows in C#. Here is how to iterate through attachments and

using Microsoft.Graph; using Azure.Identity; var scopes = new[] { "https://microsoft.com" }; var options = new ClientSecretCredentialOptions { AuthorityHost = AzureAuthorityHosts.AzurePublicCloud, }; var clientSecretCredential = new ClientSecretCredential( tenantId, clientId, clientSecret, options); var graphClient = new GraphServiceClient(clientSecretCredential, scopes); Use code with caution. 3. Locating the Message and Attachments Register your app in the Microsoft Entra admin center

There are two main types of attachments: FileAttachment (standard files) and ItemAttachment (other emails or calendar items attached). Most use cases focus on FileAttachment . Handling Large Attachments

Register your app in the Microsoft Entra admin center .

Downloading Outlook Email Attachments via Microsoft Graph API in C#

var messageId = "YOUR_MESSAGE_ID"; var userId = "user@example.com"; // Fetch all attachments for the message var attachments = await graphClient.Users[userId] .Messages[messageId] .Attachments .GetAsync(); foreach (var attachment in attachments.Value) { // Check if it's a file attachment if (attachment is FileAttachment fileAttachment) { string fileName = fileAttachment.Name; byte[] contentBytes = fileAttachment.ContentBytes; // Save to local path string folderPath = @"C:\Downloads\Attachments"; File.WriteAllBytes(Path.Combine(folderPath, fileName), contentBytes); Console.WriteLine($"Downloaded: {fileName}"); } } Use code with caution. 5. Handling Large Attachments