0
votes

I'm trying to send emails in my Symfony 4.4 app, I tryed both Mailer and SwiftMailer.

The app is running inside a Docker container, with shared ports 80 and 3306.

If I try the console command with SwiftMailer I get this:

bin/console swiftmailer:email:send [email protected] [email protected] --subject=hi --body=hi

[OK] 1 emails were successfully sent.

And after a while I get:

ERROR [app] Exception occurred while flushing email queue: Expected response code 250 but got code "554", with message "554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. [Hostname=XXXX.eurprd04.prod.outlook.com]

This happens with other email providers also, and both, in Mailer and SwiftMailer.

The fact that I get an (error) response from the service provider (Outlook in this case) makes me think that is not a port problem, as the email did actually reach the provider.

Any ideas? I'm quite stuck on this.

Thank you.

1

1 Answers

1
votes

This is an outlook365 issue, your authentication account is different to the From address, this is forbidden unless you explicitly grant permission to do so.

You can easily solve this by using the same From address as the account you are using to authenticate. Otherwise, you'll need to grant SendAs permission or SendOnBehalf.

Given your example, you need to set the permission on the [email protected] mailbox, and grant it to the [email protected] user as configured in your env.

You need to do this for as many mailboxes as you want the authuser to be able to send mail as.

To check the configuration, you can access Office 365 as the authuser and try changing the From address when composing a new email. You should see all addresses that have granted permission to that user.