Skip to main content

Email through Microsoft 365

So that alerts reach you by email from your Microsoft 365, with no SMTP or mailbox passwords. You do it once, under Alerts & SIEM → Add output → Email, with How it is sent: Microsoft 365 (modern authentication). The screen has a wizard with everything to paste; this is the complete procedure.

Before you start: the sender mailbox. Emails are sent from a mailbox in your Microsoft 365. Use a shared mailbox (for example sugardaddy@yourcompany.com), not a person's: it needs no license and doesn't depend on that person staying at the company. If you don't have one, step 3 creates it (New-Mailbox -Shared).

Step 1. Create the application (Azure Cloud Shell, Bash). Open shell.azure.com in Bash with an administrator account and paste the wizard's script ("Copy the script"). It creates the "Sugardaddy correo" application with the application permission Mail.Send and its admin consent, and generates a secret that expires in 2 years. At the end it prints three values: write them down.

  • Tenant ID
  • Application ID (also needed in step 3)
  • Secret (shown only this once)

Step 2. Fill in the form.

On the screenWhat goes in it
Tenant IDthe tenant ID the script printed
Application (client) IDthe application ID the script printed
Sender mailboxthe shared mailbox, e.g. sugardaddy@yourcompany.com
Recipientswho receives the alerts, separated by commas
Application secretthe secret the script printed

Step 3. Restrict the application to that mailbox (Azure Cloud Shell, PowerShell). Application Mail.Send can send as any mailbox in your tenant; it has to be restricted to the sender mailbox. As soon as you have typed the mailbox and the application ID, the wizard shows the commands already filled in ("Copy the commands"): there is nothing to change by hand. In Cloud Shell, switch to PowerShell and paste them. They start with Connect-ExchangeOnline (it asks you to sign in with an Exchange administrator account) and do this:

Connect-ExchangeOnline
$buzon = "sugardaddy@yourcompany.com" # the one you typed in the form
$app = "…" # the application ID from the form
# create the shared mailbox if it doesn't exist yet
if (-not (Get-Mailbox -Identity $buzon -ErrorAction SilentlyContinue)) { New-Mailbox -Shared -Name "Sugardaddy" -PrimarySmtpAddress $buzon }
# 1) the group with the mailbox
New-DistributionGroup -Name "Sugardaddy remitentes" -Type Security -Members $buzon
# 2) the policy: the application can only use the mailboxes in that group
New-ApplicationAccessPolicy -AppId $app -PolicyScopeGroupId "Sugardaddy remitentes" -AccessRight RestrictAccess -Description "Sugardaddy only sends from its own mailbox"
# 3) the check
Test-ApplicationAccessPolicy -Identity $buzon -AppId $app

(The wizard's commands already carry your values and first check what already exists, so they can be pasted again.) The last line must say AccessCheckResult: Granted. The policy takes up to 1 hour to apply: in the meantime sending may fail with a 403, and the output says so.

When it says Granted, tick "I have already restricted it to this mailbox" on the output and save: the warning about restricting the application goes away. If you change the sender mailbox or the application, that box is unticked on its own, because the restriction was for the previous mailbox.

Step 4. Test. Save the output and click Send test.

If you didn't write the values down (in Cloud Shell, Bash):

  • The application ID: az ad app list --display-name "Sugardaddy correo" --query "[].{id:appId, creada:createdDateTime}" -o table
  • The secret cannot be viewed again; generate a new one (it expires in 2 years) and put it in the output: az ad app credential reset --id "$(az ad app list --display-name 'Sugardaddy correo' --query '[0].appId' -o tsv)" --display-name sugardaddy --years 2 --query password -o tsv (it finds the application by its name; the wizard gives it with the ID you have typed in).
  • The tenant ID: az account show --query tenantId -o tsv.