5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied;
Home » BLOG » WordPress » SendAsDenied error when sends an email using Office365

SendAsDenied error when sends an email using Office365

category:  Web development, WordPress
1 min read

Recently I work with one of my client WordPress websites that uses the Microsoft Office365 as mail sending. I already configured the mail sending in WordPress. Everything seems correct. However, I check the PHP error log and I found the error message says:

"STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied"

Cause

The Microsoft Office365 SMTP server is rejecting the set “From” address.

Solution

The email account that you set in the mail configuration, must present in “From” field of the outgoing emails.

For example, you use your Office365 email account as “send@yourdomain.com” in the mail configuration. It means you website will send an email out using Office365 with “send@yourdomain.com” email account. To get rid of the SendAsDenied error, in all “From” field for the email settings in your website, the email must be “send@yourdomain.com” ONLY.

Fixing in WordPress

In WordPress, you can add the snippet code below in your functions.php file at the active theme.

add_filter('wp_mail_from', 'change_contact_from_address', 999);
function change_contact_from_address() {
     return 'send@yourdomain.com';
}

With wp_mail_form filter, we will make sure the “Form” field in the email settings in your WordPress website, will use “send@yourdomain.com” ONLY. We pass 999 which is the highest priority to make sure that nothing will override our setting.

Additional fixing in Woocommerce in WordPress

If your site uses the Woocommerce plugin, you must set the “From” field at the Emails setting.

And that’s it. Happy developing day!