Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel cannot send mail through Office 365 / Microsoft 365 SMTP

ErrorUnable to send SMTP mails using office365 settings

Short answer

Four things block Office 365 SMTP from Laravel. SMTP AUTH is off for the mailbox or tenant, basic authentication is blocked by security defaults or policy, the port or TLS settings are wrong, or the From address is not the signed-in mailbox. Check the server reply first; it names which one.

  • Applies to Laravel 12, PHP 8.3, Exchange Online
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Reproduce the failure outside Laravel, so you see the server's own reply. Open a STARTTLS session to the Microsoft server on port 587 and try to authenticate.

    openssl s_client -starttls smtp -connect smtp.office365.com:587 -crlf
  2. 2Match what you see, then jump to its fix

    1. 1Authentication is rejected although the password is rightSMTP AUTH is disabled for the tenant or the mailboxFix
    2. 2Login fails with a correct password, and SMTP AUTH is enabledBasic authentication is blocked or being retiredFix
    3. 3Connection times out, or the handshake fails before loginWrong host, port or TLS settingFix
    4. 45.7.60 SMTP; Client doesn't have permissions to send as this sender.The From address is not the mailbox that signs inFix

What does the error look like?

  • Unable to send SMTP mails using office365 settings
  • 5.7.60 SMTP; Client doesn't have permissions to send as this sender.

Cause 1 of 4

SMTP AUTH is disabled for the tenant or the mailbox

1Check

SMTP AUTH is disabled by default for organizations created after January 2020. A per-mailbox setting overrides the organization one. Read both values in Exchange Online PowerShell.

Get-TransportConfig | Format-List SmtpClientAuthenticationDisabled
Get-CASMailbox -Identity sender@example.com | Format-List SmtpClientAuthenticationDisabled

2Fix

Enable SMTP AUTH for that mailbox only. In the Microsoft 365 admin center the same switch is Mail > Manage email apps > Authenticated SMTP.

Set-CASMailbox -Identity sender@example.com -SmtpClientAuthenticationDisabled $false

3Verify

The property reads False for the mailbox, then send a test message from Laravel.

Get-CASMailbox -Identity sender@example.com | Format-List SmtpClientAuthenticationDisabled

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 4

Basic authentication is blocked or being retired

1Check

SMTP AUTH is already disabled when security defaults are on, and an authentication policy that disables basic authentication for SMTP blocks it even if the settings above are on. Microsoft also schedules basic authentication for client SMTP submission for deprecation.

# ask the tenant administrator whether security defaults or an authentication policy blocks basic authentication for SMTP

2Fix

Use OAuth (modern authentication) for the SMTP connection. For internal recipients only, Microsoft points to High Volume Email, and for internal and external mail to Azure Communication Services Email. Basic authentication stays an option only where the policy allows it.

# no Laravel code change fixes this: choose OAuth, HVE or Azure Communication Services as the sending route

3Verify

Send a test message after the new route is set up.

php artisan tinker

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 4

Wrong host, port or TLS setting

1Check

Client SMTP submission uses the DNS name smtp.office365.com on port 587 (25 also works) with STARTTLS and TLS 1.2 or 1.3. Port 465 is not supported, and a firewall or ISP may block port 25.

nc -vz smtp.office365.com 587

2Fix

Set the host to smtp.office365.com, the port to 587 and TLS/STARTTLS on in your mail settings. Do not use an IP address.

# mail settings: host smtp.office365.com, port 587, STARTTLS enabled

3Verify

The connection test shows the port open, then Laravel sends.

nc -vz smtp.office365.com 587

Confirmed by learn.microsoft.com

Did this fix it?

Cause 4 of 4

The From address is not the mailbox that signs in

1Check

The address of the signed-in mailbox appears as the sender. If your app sends from a different address, the signed-in account needs Send As permission on that mailbox.

grep -rn "MAIL_FROM_ADDRESS" .env config/mail.php

2Fix

Either set the global from address to the authenticated mailbox, or have an administrator give the signed-in account Send As permission on the other mailbox.

// config/mail.php
'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'sender@example.com'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],

3Verify

Send a test message and confirm no bounce arrives.

php artisan config:clear

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Plan for OAuth or an API-based sender now, because basic authentication for client SMTP is scheduled for retirement.
  • Enable SMTP AUTH per mailbox, not for the whole organization.
  • Keep one sending address that matches the signed-in mailbox.
  • Stay under the client submission limits: 30 messages per minute and 10,000 recipients per day.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.