SMTP on Office365 not working

I found part of the the solution here:

But the code was a little wrong, and I’ve corrected it here:
(Note each step should be entered and executed separately, and you also have to make sure that the Office 365 Default Security Settings are turned off (see below).)

specify domain and admin credential

$domain=‘yourdomain.co.uk
$credential = Get-Credential

Install Module and connect to ExchangeOnline

Install-Module -Name ExchangeOnlineManagement
Connect-ExchangeOnline -Credential $credential -ShowProgress $true

Disable the global permission for SMTP authentiation (it’s already disabled by default)

Get-TransportConfig | Format-List SmtpClientAuthenticationDisabled
Set-TransportConfig -SmtpClientAuthenticationDisabled $false

Enable SMTP transport for the specific user

Get-CASMailbox -Identity relay.user@yourdomain.co.uk | Format-List SmtpClientAuthenticationDisabled
Set-CASMailbox -Identity relay.user@yourdomain.co.uk -SmtpClientAuthenticationDisabled $false
Get-CASMailbox -Identity relay.user@yourdomain.co.uk | Format-List SmtpClientAuthenticationDisabled

Changing Office365 default Security Settings:

  1. Microsoft 365 admin center
  2. Select, All Admin centres
  3. Select Entra Id Admin (Microsoft Entra admin center)
  4. Select: Identity>Overview
  5. On the Overview page, find the Properties option across the top of the information area.
  6. Scroll down to bottom of the Properties view and select: Manage security defaults
  7. Select: Disabled (not recommended)

You can actually go straight to steps 6. and 7. but I included the full steps in case anyone needs to find it via their Office365 Admin page.

I’ve now tested this a few times sending out Estimates and Invoices to a Test Clioent account I created and all is fine.
However, there is still the possibility that it all stops working if and when MS stop their support for SMTP next year.
Exchange Online to retire Basic auth for Client Submission (SMTP AUTH) - Microsoft Community Hub