Summary:
Microsoft is making changes to Microsoft 365 authentication, and the current username/password method will no longer work. This requires a new authentication method called OAuth2. Cargas has implemented a new email sending mechanism that adapts to this change.
If you use Microsoft 365 to send emails such as invoices and statements to your customers from Cargas Energy, you will need to take immediate action so that emails will continue arriving in your customers’ inboxes after March 2026.
Your Microsoft 365 admin must perform crucial configurations in Microsoft Entra ID (formerly Azure AD) and Microsoft 365, in order to use the new OAuth2
This is Step Two of the Two Part process:
-
Overview Guide: Microsoft 365 and Outgoing Email from Cargas Energy
- Configure Microsoft 365 Email Sending in Cargas Energy (Previous Step)
- Prepare your Microsoft 365 Tenant for Email Sending from Cargas Energy (You Are Here)
Process:
To setup your Microsoft Entra and Microsoft 365 tenant for outgoing email from Cargas Energy, the following steps are needed:
- Identify your Microsoft 365 Administrator
- Create a New App Registration in Microsoft Entra
- Configure permissions
- Upload the certificate
- Enable SMTP Authentication in Microsoft 365
- Create Service Principal and Allow Email Sending
1. Identify your Microsoft 365 Administrator
Microsoft Entra (formerly Azure Active Directory) is the identity system that manages access to your Microsoft 365 services. Even if you haven’t directly worked with it before, if your organization uses Microsoft 365 (Outlook, Teams, etc.), you already have an Entra tenant. This guide will walk you through creating an app registration with the necessary permissions to allow Cargas Energy to continue to send emails through your Microsoft account.
Requirements to Begin:
- Identify your Microsoft 365 administrator.
- Ensure they can log in at admin.microsoft.com and also have access to entra.microsoft.com and can see the “Applications” option in the sidebar there. If they don’t have admin access, you’ll need to contact your IT department or the person who manages your Microsoft 365 subscription. If you purchased Microsoft 365 through a partner or reseller, ask them to help identify the appropriate administrator or temporarily grant you the necessary permissions to complete this process.
2. Create a New App Registration in Microsoft Entra
Once logged into entra.microsoft.com, go to the sidebar at the left and:
- Select “Applications” in the sidebar
- Select “App registrations” in the sidebar (below Applications)
- Select “+ New registration” just under the “App registrations” heading in the main page
- Now enter a name for this application. We recommend “Cargas Energy Outgoing Mail” so that it is abundantly clear what this is for.
- We recommend leaving “Accounts in this organizational directory only… single tenant” checked for security. You will not need a Redirect URI; leave that part blank.
3. Configure permissions
The correct permissions must be enabled in order to send email through your Microsoft 365 tenant:
- You will see a new page for your application with its own sidebar.
- Select “API Permissions” in that side bar, in the “Manage” section
- Select “+ Add a permission” in the “Configured permissions” section on the main page
- Select the “APIs my organization uses” tab
- Search for “Office”
- Select “Office 365 Exchange Online”
- Select “Application permissions”
- Scroll down until you see “SMTP” and expand it
- Select “SMTP.SendAsApp”
- Select the “Add permissions” button to save
- Select “Grant admin consent for…” to enable this new permission
- Pay Attention to the Status column for any "Not granted for..." message, you can resolve it by clicking "Grant admin consent for..." again.
4. Upload the certificate
- Select “Certificates & Secrets” in the app side bar, in the “Manage” section
- Select the “Certificates” tab
- Select “Upload certificate”
- Select the public certificate (the .cer file) you downloaded during the Cargas Energy mail setup guide.
- Enter a description such as “Cargas Energy Mail”
- Select “Add” button
5. Enable SMTP Authentication in Microsoft 365
- Go to admin.microsoft.com
- Select “Users” in the left side bar, then “Active users”
- Select the user you intend to send email as.
- Select the “Email” tab
- Select “Manage email apps”
- Now make sure that “Authenticated SMTP” is checked
- Select “Save changes” button
6. Create Service Principal and Allow Email Sending
For the final step of configuration, we must use Powershell.
- Launch Powershell by opening your Start Menu in Windows, immediately start typing the word “Powershell” and then select run as administrator
- Unless you have already installed the ExchangeOnlineManagement module, you will need to install it using the following command (it will take several seconds to download and install):
Install-Module -Name ExchangeOnlineManagement
Note: if you are unable to enter Powershell commands due to restrictive execution policies on your machine, you can temporarily relax those restrictions with the following command. Once you close your Powershell window, the restrictions will again resume, so you may need to enter this again at the next step when you launch a new window.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
- Now you can close that window and launch an ordinary powershell window by going the start menu again but this time just left-click normally, no need to launch as administror. Then import that module (if all goes well, nothing will seem to happen)
Import-Module ExchangeOnlineManagement
In the following steps, we are going to assign some variables that will be used by later commands. Take your time, and if you get one wrong, that is no problem at all; just re-enter the corrected variable assignment on a new line.
- Find your Microsoft Tenant ID and copy it. Your Tenant ID can be found in Microsoft Entra by going to Identity > Overview:
- Copy and paste the following into the Powershell window, but before hitting enter, change the part that is within quotes to your Microsoft tenant ID that you just copied:
$tenantID = "Your tenant ID here"
- Find your Application ID and Object ID by going to Identity > Enterprise applications then selecting the app registration you created earlier (note also that the Application ID is the “Client ID” someone will also need to paste into Cargas Energy):
- Copy and paste the following into the Powershell window, but before you press enter, change the Application ID to the one you copied from Entra:
$applicationID = "Your application ID here"
- Copy and paste the following into the Powershell window, but before you press enter, change the Object ID to the one you copied from Entra:
$objectID = "Your Object ID here"
- Double check: is the
$applicationIDin Powershell the same as the Application ID in Entra, and the$objectIDthe same as the Object ID in Entra? - Now set the username of account mailbox you want to send email from, replacing this fake email address with yours:
$userName = "youremail@yourcompany.example.com"
- Review the variables, then proceed when you are ready to execute commands that will use the variables you just set.
- Paste the following command in order to connect and log into your Microsoft tenant. It will open up a login prompt. Be sure to login in as a Microsoft 365 Administrator, otherwise, you won’t have sufficient privileges to perform these steps. Also, if, after entering this, you receive yellow messages from Microsoft about the new v3 EXO module, you can safely ignore them.
Connect-ExchangeOnline -Organization $tenantID
- Now we create the new email sending “service principal” by copy/pasting the following line and typing enter:
$servicePrincipal = New-ServicePrincipal -AppId $applicationID -ObjectId $objectID -DisplayName "Cargas Energy email sending"
- Finally, allow the service principal we just created to use the mailbox of the user you have designated:
Add-MailboxPermission -Identity $userName -User $servicePrincipal.ObjectID -AccessRights FullAccess
Finished!
Someone will also need to follow the Cargas Energy mail setup instructions. The person following those instructions will need both the Client ID (also called Application ID that you copied above) and the Tenant (Directory) ID if you have not already provided these.
Comments
Article is closed for comments.