17

I would like to send an email with an attachment. Using smtp.office365.com

IN Production: ubuntu

smtp.office365.com - Laravel 5.

Expected response code 250 but got code "554", with message "554 5.2.0 STOR EDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message.

IN Localhost :

Expected response code 250 but got code "530", with message "530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [xxxxxx.xxxx.PROD.OUTLOOK.COM]"

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD='xxxxx'
MAIL_ENCRYPTION=tls
Sathiya
  • 173
  • 1
  • 1
  • 6
  • Are you changing the `From` address? – GrumpyCrouton Oct 11 '18 at 16:54
  • [Possible dupe for production error](https://stackoverflow.com/questions/40016305/phpmailer-exceptionsendasdeniedexception-mapiexceptionsendasdenied) - [Possible dupe for localhost error](https://stackoverflow.com/questions/30342884/the-server-response-was-5-7-57-smtp-client-was-not-authenticated-to-send-anony?noredirect=1&lq=1) – GrumpyCrouton Oct 11 '18 at 16:56
  • Yes I changed from address. – Sathiya Oct 11 '18 at 16:57
  • 1
    I am currently experiencing this exact issue. I am investigating will post results here. – Chris Richardson Nov 06 '18 at 16:37

3 Answers3

44

For Office 365, From_Email must be the same as the logon user. You are changing the From address, and that is not allowed.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Ali Shahnazi
  • 616
  • 1
  • 7
  • 7
  • I believe you can as long as the permissions are set. I've got an application that is sending using the email from the env that has permissions to send from another email. – cbloss793 Jan 06 '20 at 16:04
6

Change your setting in mail.php file

'host' => env('MAIL_HOST', 'your-mail-host'),
  'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Your User Name'),
    ],
1

I was using this to test:

Mail::send('welcome',[],function($message){ $message->to('[email protected]')->subject('laravel mail'); });

This code made this error

Swift_TransportException with message 'Expected response code 250 but got code "554"

I added a from clause that matched my config in .env

Mail::send('welcome',[],function($message){ $message->from('[email protected]')->to('[email protected]')->subject('laravel mail'); });

I got the email.

Chris Richardson
  • 330
  • 3
  • 11