Problem sending email from Microsoft 365

I have looked into the many topics in this forum that have discussed this issue without luck.
I’ll try to provide enough details here so hopefully, we can find a clear solution for the issue.

When configuring OJS 3.2.1.0 with a Microsoft 365 email account, no mail will be delivered, producing the following error message:

[Sun Jun 27 15:05:53.398408 2021] [php7:notice] [pid 14469] [client 31.214.38.73:50089] SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: 5.2.252 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message.

The email account is a university account provided by Microsoft. I have checked the credentials, which work fine when authenticated on Microsoft’s website.

Here’s my config.inc.php email section (anonymized with …):

;;;;;;;;;;;;;;;;;;

; Email Settings ;

;;;;;;;;;;;;;;;;;;

[email]

; Use SMTP for sending mail instead of mail()

smtp = On

; SMTP server settings

smtp_server = smtp.office365.com
smtp_port = 587

; Enable SMTP authentication

; Supported mechanisms: ssl, tls

smtp_auth = tls

smtp_username = “…”

smtp_password = “…”

; Allow envelope sender to be specified

; (may not be possible with some server configurations)

; allow_envelope_sender = On

; Default envelope sender to use if none is specified elsewhere

; default_envelope_sender = my_address@my_host.com

; Force the default envelope sender (if present)

; This is useful if setting up a site-wide no-reply address

; The reply-to field will be set with the reply-to or from address.

; force_default_envelope_sender = Off

forced_from_address = …

This page (GitHub - grantj-re3/FlindersOJS-email: Allow OJS v3 email to comply with SMTP AUTH client submission such as offerred by Microsoft Office 365.) suggests using forced_from_address, which does not seem to matter in this configuration file.

Is there any clear way to overcome this problem?

Thanks.

While I don’t have any experience with Microsoft 365, I suggest turning allow_envelope_sender On and force_default_envelope_sender On (remove the semi-colons) and then adding the same email address as in the smtp_username to the default_envelope_sender line.

The error seems to suggest that sending “as” whoever wrote the email is not allowed, which is how your configuration is currently set up. Enabling those options I mentioned will create something like:

From: the address in the force_envelope line
Reply-To: the email address of the OJS user who sent the email

which is usually how things need to be.

Best,
Jason