skip to Main Content

I am trying to send an email over smtp from Laravel using outlook business email. I am using TLS 1.2, And I activated SMTP settings for email from admin center active users panel, and I am using the following:

MAIL_MAILER=smtp
MAIL_HOST=smtp.office365.com
# MAIL_HOST=smtp-mail.outlook.com
# MAIL_HOST=smtp-legacy.office365.com
# MAIL_HOST=smtp-legacy.partner.outlook.cn
MAIL_PORT=587
[email protected]
MAIL_PASSWORD="app_password" #from MFA
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

But I am having this error: with message "535 5.7.3 Authentication unsuccessful. Note that the commented MAIL_HOSTS are links I tried with the same result.

Also I tried port 25 with error Connection could not be established with host "smtp-mail.outlook.com:25

Note that I am using this Laravel’s mailer:

'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'local_domain' => env('MAIL_EHLO_DOMAIN'),
        ],

Any fix?

2

Answers


  1. I can’t comment that is why I’m posting as an answer. My reputation is not allowing me to comment.

    I’ve faced similar kind of issue when I was trying to send using gmail. As per my knowledge, Gmail, Office365 has upgraded their security feature. Now you can’t use your email password for sending the mail.

    You have to enable two-factor authentication first, then you can get access to create app-password for your use. Use that app-password instead of your email password. Note: app-passwords you have save it somewhere, once you close that window, you won’t be able access it again.

    https://support.microsoft.com/en-us/account-billing/using-app-passwords-with-apps-that-don-t-support-two-step-verification-5896ed9b-4263-e681-128a-a6f2979a7944

    Login or Signup to reply.
  2. Your coding part is fine. The host should be smtp.office365.com. But you also need to enable some settings for your sender. You have to use the SMTP client submission. Microsoft allows 3 options to send email via SMTP. This is the Microsoft documentation

    Most importantly, your sender email address should have an Exchange Online license. You cant do this with a shared mailbox. Then your mailbox should be enabled for sending SMTP emails.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search