M365: Microsoft Graph – Part 11 – Send Email using Graph API from .Net Core Application with attachments

.Net Core application to send email using Graph API

Hi All,

LIFE IS BEAUTIFUL 🙂 I hope we all are safe:) STAY SAFE, STAY HEALTHY 🙂 STAY HOME 🙂

Today again with my favorite feature “Microsoft Graph”. This is sequel of my previous Graph Article – M365: Microsoft Graph – Part 10 – Send Email using Graph API from Console Application (Background Job) 🙂

On this article one of friend asked for sending attachment as well. So thought why not to write an article 🙂

So in this article I wont get in detailed steps as already mentioned in article but will have only new changes.

In last article I have used Console Application with .Net Standard Framework, this time tried with .Net Core Framework as

M365 - Graph APIs - .Net Core Console Application
Fig1: M365 – Graph APIs – .Net Core Console Application

Please refer last article for M365: Microsoft Graph – Part 10 – Send Email using Graph API from Console Application (Background Job) for following points

Since this is .Net Core application, I am storing Azure App Key and Secret in JSON file – appsettings.json file as

M365 - Graph APIs - .Net Core Console Application - Storing details in JSON file
Fig2: M365 – Graph APIs – .Net Core Console Application – Storing details in JSON file

Following references required

M365 - Graph APIs - .Net Core Console Application - Sending Email using Graph APIs - References required
Fig3: M365 – Graph APIs – .Net Core Console Application – Sending Email using Graph APIs – References required

Following is the code to read JSON file from .NET CORE

Now how to send attachments: There is a class calledMessageAttachmentsCollectionPage used to add multiple FileAttachment attachments as

Then we have two properties for Message object –

  • HasAttachments : boolean property which indicates whether message has attachments or not
  • Attachments : collection of Attachments which we need to send. Instance of MessageAttachmentsCollectionPage class

Following is the sample of complete Message object

Following is the complete code

AzureAuthProvider class code:

We have very good series of articles on “Microsoft Graph” and will be coming a lot. Please visit – https://knowledge-junction.com/?s=Microsoft+graph

For any query related to Microsoft Graph feel free to ping me 🙂

Thanks for reading 🙂 If its worth at least reading once, kindly please like and share. SHARING IS CARING 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: