Support-ending notice

Early November 2022, ownership of the Mail Integration for Office 365 / Outlook plugin transferred to WPO365. We are committed to provide (best-effort based) support for this plugin until the end of 2023.

To ensure, however, that we are able to provide you with long time support, we urge you to download and install the WPO365 | MICROSOFT GRAPH MAILER plugin for WordPress instead (and de-activate the Mail Integration for Office 365 / Outlook plugin and remove it from your WordPress website).

If you have already installed and configured the  Mail Integration for Office 365 / Outlook plugin, then please make sure to check out our easy-to-understand online migration guide.

– Marco van Wieren | Downloads by van Wieren | https://www.wpo365.com/

So I’ve finally got around to officially publishing my first WordPress plugin: Mail Integration for Office 365 by Cross Connected – WordPress plugin | WordPress.org

It’s by no means the first plugin I’ve ever written, but to date my exploits have solely focused on developing plugins that meet my own requirements; filling niche gaps that are hardly mass market. However, I think I’ve finally spotted a gap that could have some legs – the ability to connect WordPress to Office 365 to send emails from an Exchange/365 account!

Up until recently it has been possible to connect to Office 365/Exchange server via SMTP. However, Microsoft have now disabled basic authentication over SMTP by default, requiring more modern authentication methods.

You can re-enable basic authentication, but if you use two factor authentication (which you should by the way!), this can cause issues. It is also far less secure than OAuth2 (the authentication protocol this plugin uses), and Microsoft are right to disable it in an age of GPU password cracking and brute force attacks!

Now don’t get me wrong, there are plugins out there that will connect you to Office 365/Exchange. However, the ones I’ve found only provide this through a paid for feature/addon. Given that Office 365 is itself a paid for service, to my mind that is a little annoying.

For this reason I’ve made this free plugin for all to use and hopefully benefit from. It’s a little convoluted to set up, but that’s the nature of OAuth2 I’m afraid. However, if you’re patient and follow the guide found here diligently, you should be able to get it up and running pretty quickly.


49 Comments

Tim Turner · 25th January 2021 at 7:19 pm

Hi Edward,
Not sure where else to try and reach out for support but I’ve followed the guide and have everything setup but when I got to submit my form on my site, I get a “REST API is not yet supported for this mailbox.” message at the top of the page. I know you mentioned about M$ not enabling the graph API to work with free M$ account but I have paid office 365 business account, not even sure this would be related to that or not.

    Edward · 25th January 2021 at 11:49 pm

    Hi Tim, so couple of things come to mind.

    Firstly, are you sure you’re registering the right account with the plugin? Make sure your browser hasn’t saved your personal hotmail/live details and isn’t logging you in with those rather than the account you wish to authorise the plugin with. The easiest way to check this is to open the WordPress admin via an in private/incognito browser window that will force you to enter your login details for the account you wish to authorise after clicking the authorise button.

    Second thing to check if that doesn’t resolve things, is to see if you have your Office 365/Exchange licence assigned to the account you’re attempting to register within the admin portal of 365 (may seem obvious, but you can create a user within 365 with no licences). If you’ve set up a user such as admin@domain, or noreply@domain, these would also need a separate 365 mail licence assigned, unless you set these up as shared mailboxes.

    Third thing to check (which may not be relevant in your case, but still worth checking), is that your account has been migrated over to 365 as explained in this guide: https://docs.microsoft.com/en-us/exchange/troubleshoot/user-and-shared-mailboxes/rest-api-is-not-yet-supported-for-this-mailbox-error

David Sandil · 29th January 2021 at 2:20 pm

Wonderful plugin. I have configured the plugin as required. Thanks to your detailed steps. It worked for a day may be and then it stopped sending emails. When I go to the plugin page and authorise it again, it get authorised successfully but finally when I press save button, it shows error – ‘Invalid OAuth State’ at the top of the plugin settings page. Any idea?

    Edward · 30th January 2021 at 10:19 am

    Hi David, so if you’re not using version 1.3.0 then that might explain things. A few people were having this issue with version 1.2 but it was resolved in version 1.3.0 (according to the same users). If you are using version 1.3.0, then I’d try removing the plugin completely (making sure you haven’t chosen to remember the credentials in the plugin settings page). Deactivate and then delete the plugin, redownloading it again. It’s unlikely, but I guess possible, that there could be an issue with the transition between 1.2 and 1.3, causing the invalid state error as I changed the way I was recording the state variable in temporary storage between the two versions.

Tyler Reed · 4th February 2021 at 4:23 am

When I click save settings I get this:

Error: Options page mail-integration-365-settings_deactivation_options not found in the allowed options list.

What do I need to fix?

    Tyler Reed · 4th February 2021 at 4:29 am

    Fixed it, followed the instructions on the post above.

Fred · 5th February 2021 at 7:46 am

Greetings! First, thanks for this plugin, it is what I need. BUT I followed the very good instructions, and everything looks good. Until i save the settings, then I get ‘Invalid OAuth State´And in the Office 365 email account trying to send from my WordPress I get delivery failure 550 5.7.708 Service unavailable. Access denied, traffic not accepted from this IP. I suspect I need to do something in Office 365? Im a admin.

    Fred · 5th February 2021 at 7:49 am

    Forgot to mention, Im using latest version, tried deactivate, delete, reinstall, same issue.

        Fred · 6th February 2021 at 7:06 pm

        I already have tried that solution, no luck.

          Senne · 27th February 2021 at 10:55 am

          Hi Edward and Fred,
          I have no issues in seeting it up but I do get the “550 5.7.708 Service unavailable. Access denied, traffic not accepted from this IP” NDR… It’s a rather new O365 tenant but I have no idea what to try next… Fred, were you able to get yours working? Did you contact Microsoft directly?

          What IP are they not trusting? The one where the WordPress website is hosted and that is calling the Graph API?

          Thanks for pointing me in the right direction, your plugin is absolutely what I was looking for, almost there 🙂

          Edward · 28th February 2021 at 6:48 pm

          Hi, so it must be the IP of the WordPress website. If you are using a shared server which hosts multiple websites under the same IP, it’s possible that other websites used for spam or nefarious purposes have caused the IP address to be flagged by Microsoft. Many cheaper/free web hosting services are shared services. This may not apply in your case, but it seems to be a potential reason for the issue you’re facing, without knowing the details of your web hosting.

Lennart · 28th February 2021 at 12:34 pm

Hi Edward,

first of all, thank you so much for this wonderful plugin! It’s amazingly simple and lightweight. Great work! 👌

I do have one issue though: I use Contact Form 7 and after I submit a form (send a message), the loading animation keeps going on. There is no response (i.e. “successfully sent”) for the user who sends a message. This only happens when activating your plugin; the standard email sending function works. Are you aware of that or is it something with my individual configuration?

I’m very much looking forward to hearing back from you! 🙂

Lennart Wörmer · 28th February 2021 at 12:39 pm

Hi Edward, I have just discovered that the problem is caused by the Mail (2) function of Contact Form 7. If you deactivate it, it works perfectly. Having it activated causes the issue. The second email won’t be sent either.

    Edward · 28th February 2021 at 6:49 pm

    Hi Lennart, I did have issues getting Contact Form 7 to register that an email had been sent, but glad you’ve found a work around.

      Edward · 13th April 2021 at 5:22 pm

      Just to say I think the Contact form 7 issue has been resolved.

        Aaron · 11th May 2021 at 2:48 am

        I don’t think the issue is quite fixed.
        The plugin works for a single mail, but Mail (2) will still not send.
        This plugin does otherwise look great, so hoping it is not too hard to fix

          Aaron · 11th May 2021 at 2:51 am

          Nevermind, issue was from a separate plugin, nothing wrong with this one!

Andrew Read · 2nd March 2021 at 6:06 pm

Hello,

I am not using Mail (2) in the Contact Form 7 plugin, but my website won’t send emails through the contact form. I just get a constantly spinning dial beside the send button. Is there any way to get some support on this?

A “send test email” section in your plugin would be a great tool to let us discover if there is an issue with your plugin sending emails or if it is indeed an issue with Contact Form 7.

Thanks for your effort put into this plugin though!

    Edward · 5th March 2021 at 10:20 am

    Hi Andrew, I know I looked at this issue ages ago and couldn’t figure out a resolution. It seems, because I intercept the PHPMailer() event through using WordPress’ wp_mail() pluggable function, I have to stop the PHPMailer event to stop WordPress trying to connect over STMP, instead capturing the mail attributes and sending them via Microsoft Graph’s REST API. Whilst the wp_mail() event then returns true, it seems PHPMailer doesn’t, and because Contact Form 7 is waiting for PHPMailer to return true, it keeps the spinning animation, rather than showing a “mail sent successfully” message. I ran out of ideas/trial and error approaches to getting around this limitation, but I’m open to any ideas from others more knowledgeable than me! I think I may have to provide an alternative to use OAuth over SMTP, rather than the REST API (which I believe is what other paid for plugins use), as this will mean I don’t have to intercept and stop the PHPMailer events in order to redirect the mail request over a REST API.

      Christian Callsen · 10th March 2021 at 3:57 pm

      Hi Edward! I’m seeing the exact same problem. Is there a workaround until you can fix the plugin, please (please)? Otherwise, the plugin prevents the contact form from working.
      Cheers!
      Christian

        Edward · 13th April 2021 at 5:21 pm

        Hi both, I believe the issue with the contact forms has now been resolved.

Adrian · 11th March 2021 at 7:27 am

Hey Edward.
Thanks for the perfect plugin. It does exactly what I was looking for. The setup instructions worked like a charm.
However, I have a problem sending HTML emails. They do not arrive properly formatted to the recipient. It seems that they are sent as “text” although the contact form plugin (Form Maker v.1.13.53) is set to use HTML. If I deactivate your plugin, it works. Do you have any idea what the problem could be?
Thanks and greetings from Switzerland.
Adrian

Edward · 12th March 2021 at 7:48 pm

Hi Adrian, so I think I’ve figured out what’s going on here. I hadn’t realsied there are two ways of setting the content type of an email with wp_mail(), and one doesn’t require a content-type header. I think the Form Maker is changing the content type by a filter which doesn’t result in a content-type header being sent (at least at the function level). Given my plugin was looking for the content-type header, it wasn’t recognising that the content type of the email had changed from default text type of wp_mail(). I’ve adjusted the code to listen for the content type filter event, as well as looking at the headers (giving precedent to the header value if both exist). I’ve tested with the Form Maker plugin and this seems to have resolved the issue.

As I’ve only just released a new version, I’m probably going to leave it for a few week before pushing the new one (there may be a few more things that need updating). However, you can install the beta version from the following link (indeed it would be good to get some feedback on whether you have any issues with it anyway): https://drive.google.com/file/d/1zdfDsY3CbtTFbEO668vCs70j72y3m84C/view?usp=sharing

Here’s a guide for how to install a plugin manually (note only do so from sources you trust…): https://www.hostinger.com/tutorials/wordpress/how-to-install-wordpress-plugins

    Adrian · 13th March 2021 at 3:50 pm

    Hi Edward, thank you for the quick reply. I have installed and tested the updated version. The problem with the HTML email has been solved.
    Now I have another question: In Form Maker, a reply-to address can be defined for the email to the administrator. However, the email does not contain this information. Apparently it gets lost. If your plugin is deactivated, it works fine. Do you maybe also have a solution for this?
    Thank you and best regards, Adrian

      Edward · 11th April 2021 at 9:57 am

      Hi Adrian, the reply-to issue is something I’m aware of. If you’re technically minded, the issue is that when I’m overriding the wp_mail($to, $subject, $message, $headers, $attachments) event, the $headers variable doesn’t seem to be transferred. Hence it appears there is no reply-to header, even when one is set. It might be something obvious I’m missing, I just haven’t had the time to investigate as yet.

Edward · 13th April 2021 at 5:20 pm

Hi Adrian, I have now updated the plugin to version 1.6.0 which seems to be setting the reply-to address correctly. I think this update should have also resolved the issue with Contact Form 7 and other similar plugins.

Jose Fernando · 19th April 2021 at 5:34 pm

Hi Edward:
I have problems with the plug-in and contact form 7. The plug-in works if there is only one recipient in the “To” field of the “mail” tab of contact form 7. If there are more recipients, in DevTools I get this error: {code: “invalid_json”, message: “The response is not a valid JSON response.”}. And the mail is not sent.

    Edward · 26th April 2021 at 8:25 am

    Hi Jose, sorry you’re having issues. I’ll look into this. I have an idea of what’s going on but will need to investigate to check.

Luis · 22nd July 2021 at 12:44 am

Hi!
I am not using Mail (2) in the Contact Form 7 plugin, but my website won’t send emails through the contact form.
I followed instructions very carefully, everything without error. There is no response (just: “successfully sent”) for the user who sends a message but never arrived at any message in my box. Have a Phone number to call anyone to helpme? It´s very important to us. thanks

    Edward · 12th August 2021 at 9:38 am

    Hi, the latest version of the plugin 1.8.2 should have resolved this issue.

Ben Archibald · 10th August 2021 at 1:10 pm

Hi Edward – this plugin is excellent and has really helped us. Azure is fragile sometimes, as we know. After your last update 17 hours ago our site went down with the following error :

Warning: require(/home/usiie/public_html/wp-content/plugins/mail-integration-365/libs/vendor/composer/platform_check.php): failed to open stream: No such file or directory in /home/usiie/public_html/wp-content/plugins/mail-integration-365/libs/vendor/composer/autoload_real.php on line 25

We have rolled back to the previous version and the site is functional. I’d appreciate any thoughts you may have on it!

    Edward · 12th August 2021 at 9:39 am

    Hi,sorry, this was my mistake with the versioning system that WordPress use for their plugin repositories. Version 1.8.2 shouldn’t have any issues, but please test with a development site if you have one just in case.

Daniel · 3rd January 2022 at 8:29 pm

I’ve been using your plugin and just went to update M365 settings with a new secret, and I’m getting invalid_client AADSTS7000215: Invalid client secret is provided. error. I created a whole new app, just to be safe, meticulously copying your instructions, and the same error is thrown. Using v.1.8.4, WP v.5.8.2 and PHP v.7.3.33

    Edward · 4th January 2022 at 12:05 pm

    Hi, I think the most likely reason for this is you are copying the ID vale of the client secret rather than the client secret itself. Confusingly, Microsoft now shows two values that can be copied – you need the secret, not the ID!

Dan Hoff · 13th January 2022 at 10:24 pm

Trying to activate, and meticulously followed the step-by-step guidance but get the error code:

invalid_client AADSTS7000215: Invalid client secret is provided. Trace ID: 5e020dc2-d844-4cfe-8bba-18a625952000 Correlation ID: d5bc779d-07ff-4d0f-852a-111a57297829 Timestamp: 2022-01-13 22:00:20Z.

That was using the codes returned from my Azure integration panel.

    Dan L Hoff · 14th January 2022 at 4:44 am

    Just read your response to the question above mine, realized that it was the same issue. Made your suggested change and BOOM, it worked fine. Thanks

      Edward · 14th January 2022 at 8:55 am

      No worries, glad it’s working for you!

        Dan L Hoff · 14th January 2022 at 10:15 pm

        First, it worked. Now it doesn’t and I have not changed any settings. Should SMTP be switched on or off on my exchange server, or does that not matter.

Dan Hoff · 14th January 2022 at 11:18 pm

The issue is now resolved after a number of hours of troubleshooting. This may be of value to other users of your plugin. I had a new Exchange/O365 subscription that was in the trial period. As it seems, that trial tenant ID is, as a course, rejected by MSFT servers. That resulted in a non-delivery error code. 5.7.708. I contacted support and needed to request a wavier and once processed, the plugin worked flawlessly once again.

Andrew Read · 20th January 2022 at 5:40 pm

Hi Edward,

Just reauthorizing this plugin for the latest version (thanks for all the past fixes!) and I am having issues getting “Send As” to work with a different email address. I have the email address I want to Send As given permissions for “Send as” and “Send on Behalf of” in O365 admin for the master email address, but the emails don’t go anywhere even though the form completes. The form works without “Send As” set, but the incorrect email address sends the emails.

Anywhere I can find an error log with what is happening?

    Edward · 22nd January 2022 at 11:36 am

    Hi Andrew, you could try installing the check and log email plugin: https://wordpress.org/plugins/check-email/

    This should tell you if the mail is registering as successfully sent from WordPress, if it is then the error must be on the Azure/365 side of things, in which case you’d need to look at the logs within 365/Azure.

    If you don’t see any email log from within WordPress, then it’s probably something to do with my plugin and I’ll need to investigate.

    Ed

      Andrew Read · 31st January 2022 at 3:15 pm

      Thanks Ed, I’ll look into it.

jay · 3rd February 2022 at 6:28 pm

Hi have a question about the plugins for Office365. my email within O365 is [email protected] but I want my site to send with an adresse [email protected] or noreply@ will it work ? also I’m configure with MFA, is it possible to make work the plugins ?

Sorry to post here, it seems you contact form doesn’t send the message and keep on “processing”

    Edward · 7th February 2022 at 9:58 am

    This should work, but you’ll need to set these as alias’ within your office 365 account. MFA will work as when you authorise the plugin with your office 365 account you authenticate in the same way you authenticate for other 365 services, providing a username, password and one time passcode. This then proves to Office 365 you are who you say you are, returning an access code which is then used to exchange for an access token and refresh token which are stored in the database, the refresh token can then be used by the plugin to request a new access token once the access token expires, without the need for username, password and MFA authentication.

Sakthidasan · 12th March 2022 at 3:28 pm

Hi,
After integrating the plugin, when I’m trying to submit my pages and post to google and bing index, I’m getting the below error. Because of this, my site is not indexing. Can you please help me?

{
“readyState”: 4,
“responseText”: “There has been a critical error on this website.Learn more about troubleshooting WordPress.“,
“status”: 500,
“statusText”: “error”
}
——————————————————–

Thanks
Sakthi

Tim · 17th March 2022 at 9:43 pm

Hi Edward,

I’ve been using your plugin today but have been having issues, it appears after some hours and a password reset, the plugin is no longer sending mail.

Any idea on how to troubleshoot this?

Tim

Frank · 18th May 2022 at 9:52 am

Hi, it seems I cannot activate the plugin because my WordPress version is to high? I am currently using 5.9.3 and cannot activate the plugin.

Joe · 4th November 2022 at 8:26 pm

Hey Edward,
There was a little issue configuring the plug-in. I kept getting secret key expired error when authorizing the plugin I was beating my head against the wall trying to figure it out LOL. Not sure if it was the update that caused this but the Solution was to right click the authorize plugin to integrate and select open in new tab and bam it worked! Thanks this is a great plugin!

Comments are closed.