Microsoft offers Graph API to access the services of Office 365 and Microsoft Cloud programmatically from within your applications. Furthermore, you can use the Graph API to manage folders, send messages, and perform various other operations. In this article, you will learn how to create and send messages using Microsoft Graph API in C#.
- .NET Microsoft Graph API to Create and Send Messages
- Create Messages using Microsoft Graph API in C#
- Send Messages using Microsoft Graph API in C#
C# .NET Microsoft Graph API to Create and Send Messages
Aspose.Email for .NET is an amazing API to create and send emails from within .NET applications. In addition, it allows you to use Microsoft Graph API and manage folders, messages, etc. We will use this API to create and send messages using Microsoft Graph API. You can download the API’s DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.Email
Create a Message using Microsoft Graph API in C#
To communicate with the Graph API, you need to first implement the ITokenProvider interface for authenticating the requests. The following is the basic implementation of ITokenProvider.
The following are the steps to create a message using Microsoft Graph API in C#.
- First, get an instance of Microsoft Graph client using GraphClient.GetClient(ITokenProvider, string) method.
- Then, create an instance of MapiMessage class.
- After that, set the subject, body, and other properties of the message.
- Finally, create the message in desired folder using IGraphClient.CreateMessage(GraphKnownFolders, MapiMessage) method.
The following code sample shows how to create a message using Microsoft Graph API in C#.
Send Messages using Microsoft Graph API in C#
Let’s now have a look at how to send a message using Microsoft Graph API in C#.
- First, get an instance of Microsoft Graph client using GraphClient.GetClient(ITokenProvider, string) method.
- Then, create an instance of MapiMessage class.
- After that, set the subject, body, and other properties of the message.
- Finally, send the message using IGraphClient.Send(MapiMessage) method.
The following code sample shows how to send a message using Microsoft Graph API in C#.
Get a Free API License
You can get a free temporary license to use Aspose.Email for .NET without evaluation limitations.
Conclusion
In this article, you have learned how to use Microsoft Graph API to create and send messages in C#. You can simply install Aspose.Email and integrate the provided code samples into your .NET applications. In addition, you can have a look at other features offered by Aspose.Email for .NET using the documentation. Also, in case you would have any questions, you can post to our forum.