參考:https://stackoverflow.com/questions/52765247/expected-response-code-250-but-got-code-554-with-message-554-5-2-0-stor-edr
.env配置如下:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD='xxxxx'
MAIL_ENCRYPTION=tls
報錯資訊:
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.
原因:
off365的發件人必須和登入使用者一緻。
在laravel中的config/mail.php可以看到
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
解決辦法:
在.env增加一行配置:
MAIL_FROM_ADDRESS=(這裡的位址和MAIL_USERNAME相同)