# Microsoft 365 mail sender

## Overview

> **IMPORTANT**: This service is available as of Sitefinity CMS  version 14.4.8123. Dependency mismatch is possible in case the order of the steps in this article is not followed.

You can configure your notification profile to use Microsoft 365 and SMTP servers. First, you must register your application in Microsoft Entra ID and ensure it has the proper permissions.

1. Create or use your Microsoft Exchange registration to access the Azure portal. For more information, see Microsoft documentation » [Exchange Online](https://www.microsoft.com/en-us/microsoft-365/exchange/exchange-online).
2. Log in to the Azure portal at <https://portal.azure.com/> with your registration where you Microsoft Entra ID resides in.
3. Go to Microsoft Entra ID and add a new app registration.\
   For more information, see Microsoft documentation » [Register an app with Microsoft Entra ID](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/walkthrough-register-app-azure-active-directory).
4. For *RedirectURI* add `https://www.microsoft.com/en-us/microsoft-365/exchange/exchange-online` and from the dropdown box, choose *Web*.
5. Once the app is registered, open it to add API permissions.
6. Add the following Microsoft Graph permissions as application permission type:

   * `Mail.Read`
   * `Mail.ReadBasic`
   * `Mail.ReadBasicAll`
   * `Mail.ReadWrite`
   * `Mail.Send`

   For more information, see Microsoft documentation » [Delegated permission to Microsoft Graph](https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-configure-app-access-web-apis#delegated-permission-to-microsoft-graph).
7. From the APIs your organization use, add the following Office 365 Exchange Online permission as application permission type: 
   * `SMTP.SendAsApp`
8. Create a new secret.\
   For more information, see Microsoft documentation » [Add a client secret](https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app#add-a-client-secret). \
   Make sure to save the secret value for later as you need it to complete the setup.
9. Get your *Application (client) ID* and *Directory (tenant) ID* from your newly registered app overview page in Microsoft Entra ID.

## Installation

You must install a custom notification sender project to be able to use your Microsoft 365 app with Sitefinity CMS. Perform the following:

1. Download the mail sender solution from this [GitHub repository](https://github.com/Sitefinity/sitefinity-office365-mail-sender).
2. Copy the *Progress.Sitefinity.Office365.Mail.Sender* folder and paste it in the same directory as your Sitefinity CMS solution.
3. Open your Sitefinity CMS solution with Visual Studio.
4. In case the mail sender project is not visible under your Sitefinity CMS solution, import it manually by right clicking on the solution » *Add* » *Existing project*.
5. Add a reference to the mail sender project from your `SitefinityWebApp`.
6. Build the entire solution.

To use the Microsoft 365 mail sender, you must install `Microsoft.Graph.Core` in your `SitefinityWebApp` project using the following command:

`Install-Package Microsoft.Graph.Core -Version 3.0.6`

This is done to ensure there are no dependency conflicts between the mail sender and your Sitefinity CMS project.

## Set up the Mail Sender in the Sitefinity CMS backend

Finally, you need to configure the new profile in Sitefinity CMS backend.

1. Go to *Administration » Settings » Advanced » Notifications » Profiles*. \
   A new profile called *Office365*is now available.
2. Add the respective values to the fields *TenantId*, *ClientId*, and *ClientSecret* in this profile.
3. Fill out the *DefaultSenderEmail* and the *Host* fields as they are required for the service.\
   For the *Host* field you can fill out `Office365` for example.
4. Save your changes.
5. Go to *Notifications » DefaultProfiles » smtp*.
6. Set the new *ProfileName* to be `Office365`.
7. Save your changes.

To use email campaigns, you need to configure the Office365 profile as the Newsletters SMTP profile:

1. Navigate to *Administration » Settings » Advanced » Newsletters*.
2. Type `Office365` in the *Notifications SMTP Profile* field.
3. Click *Save Changes*.

## Test the mail sender

To test the mail sender, perform the following:

1. Navigate to *Administration » Settings » Email settings*.
2. Click *Send Test Email*.
3. Fill out the email that would receive the test message.
4. Click *Send test*.
