# Oauth Office 365 and email collector

**URL:** <https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437>\
**Category:** Using my Dolibarr\
**Created:** [March 9, 2023, 2:06pm UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437 "2023-03-09T14:06:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![FAdo84](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@FAdo84](https://www.dolibarr.org/forum/u/FAdo84)\
**Post date:** [March 9, 2023, 2:06pm UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/1 "2023-03-09T14:06:18Z")

</div>

Hi,  
I have a problem with OAuth services andemail collector. I generate the token but when I try to login in email collector I receive this error:

> > TAG1 AUTHENTICATE XOAUTH2 dX\_blabla \<\< NO AUTHENTICATE failed.

I tryed with differents scope outlook.office365 / [outlook.office.com](http://outlook.office.com) /graph.microsoft.com

> [Sign in to Outlook](https://outlook.office365.com/IMAP.AccessAsUser.All)

But I still have the same issue…

Any suggestion??

Please let me know if i do something wrong.

Dolibarr version: 17.0 / PHP 7.4 or 8.1 is the same

 ![do1](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/c/c167f5b7f28ad5fbc782d2983891c85546cb4c73.jpeg)

---

<div class="post-metadata">

**Author:** ![Plows](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/plows/32/5660_2.png) [@Plows](https://www.dolibarr.org/forum/u/Plows)\
**Post date:** [April 2, 2023, 7:53am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/2 "2023-04-02T07:53:26Z")

</div>

I am also having problems with oauth2, spending hours and receiving auth problems, my installation of dolibarr was a step by step installation “dolibarr installation and hardening” and i found some problems with my php restrictions, another reason could be problems with the returning “url”, it cost me in the end too much time and not enough help or information on the internet.  
I will be installing a test system in the near future where i can open all security settings, hopefully i find a solution.

---

<div class="post-metadata">

**Author:** ![FAdo84](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@FAdo84](https://www.dolibarr.org/forum/u/FAdo84)\
**Post date:** [April 2, 2023, 8:42am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/3 "2023-04-02T08:42:42Z")

</div>

Hi, me too. I spend a tons of hour to tried… but yesterday a glimpse of light… 🥳

premise: i’m not a programmer or developer of dolibarr… so I think it’s better to involve these persons…

Some article and test and test and test and test could be solve the problem…

interesting documentation:

[https://blog.icewolf.ch/archive/2022/12/17/exchange-online-pop-and-imap-oauth-2-0-client-credentials.aspx](https://blog.icewolf.ch/archive/2022/12/17/exchange-online-pop-and-imap-oauth-2-0-client-credentials.aspx)

[https://blog.icewolf.ch/archive/2022/12/20/exchange-online-other-ways-of-testing-imap-oauth2-client-credential.aspx](https://blog.icewolf.ch/archive/2022/12/20/exchange-online-other-ways-of-testing-imap-oauth2-client-credential.aspx)

Based on these articles now oauth works…

I share with you the code to test in the hope that the real developer try to fix the problem… I don’t know if it’s correct the workaround but it works…

/core/lib/oauth.lib.php line 35:

```auto
$supportedoauth2array['OAUTH_MICROSOFT_NAME'] = array('callbackfile' => 'microsoft', 'picto' => 'microsoft', 'urlforapp' => 'OAUTH_MICROSOFT_DESC', 'name'=>'Microsoft', 'urlforcredentials'=>'https://portal.azure.com/', 'availablescopes'=>'openid,offline_access,profile,email,User.Read,https://outlook.office.com/.default,https://outlook.office.com/.default', 'returnurl'=>'/core/modules/oauth/microsoft_oauthcallback.php');

```

/includes/OAuth/OAuth2/Service/Microsoft.php lines: 41 42

```auto
    const SOCPE_IMAP_ACCESSASUSERALL = 'https://outlook.office.com/.default';
    const SOCPE_SMTPSEND = 'https://outlook.office.com/.default';

```

I didn’t try to send an email… but the collector now works… sorry… but this is my personal fresh solution… I didn’t have time to try…  
in the next days i’ll try

---

<div class="post-metadata">

**Author:** ![Plows](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/plows/32/5660_2.png) [@Plows](https://www.dolibarr.org/forum/u/Plows)\
**Post date:** [April 4, 2023, 5:45am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/4 "2023-04-04T05:45:45Z")

</div>

I tried your solution, but no luck, i am not sure about the scopes, in my azure i have Microsoft Graph an Office 365 Exchange Online, my App ist registered as WEB App and the API Scope looks like

“https: // ps.outlook. com / IMAP.AccessAsApp”

are these two files the only you changed?

/core/lib/oauth.lib.php line 35:  
/includes/OAuth/OAuth2/Service/Microsoft.php lines: 41 42

---

<div class="post-metadata">

**Author:** ![FAdo84](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@FAdo84](https://www.dolibarr.org/forum/u/FAdo84)\
**Post date:** [April 5, 2023, 5:06pm UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/5 "2023-04-05T17:06:03Z")

</div>

Hi,  
attached my scopes:

 ![d1](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/7/794d64baedda8059c3de39271c96ad44dd8de1ad.jpeg)

I forgot 1 passage:  
in OAuth services I cofigure the permissions like the picture:

 ![d2](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/6/60b4814e77f36b70ded02e78f9aacdf02e304899.jpeg)

Another important things:  
in Microsoft Azure inside Owner add your account if you are not admin.

If you still have a problem, please enable the debug ($debug = true; in Protocol.php file) and send me the error… I’ll try to help you

Ciao!

---

<div class="post-metadata">

**Author:** ![FAdo84](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@FAdo84](https://www.dolibarr.org/forum/u/FAdo84)\
**Post date:** [April 6, 2023, 9:11am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/6 "2023-04-06T09:11:28Z")

</div>

Ciao!  
I’m busy but I tried with a fresh dolibarr installation (even 17.01).

I confirm: my solution works with office365 and email collector. I tried to send some email and it’s works.

Please if someone have my same issues please try my solution and if it works I suggest to developer of dolibarr to solve defenetily this bug.

---

<div class="post-metadata">

**Author:** ![Plows](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/plows/32/5660_2.png) [@Plows](https://www.dolibarr.org/forum/u/Plows)\
**Post date:** [April 7, 2023, 7:28am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/7 "2023-04-07T07:28:40Z")

</div>

Hi,  
i will try again tomorrow with the debug option.  
I am confused, becaus the token arrives, no problem, but get, setup authentication error, while collecting test.

---

<div class="post-metadata">

**Author:** ![Plows](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/plows/32/5660_2.png) [@Plows](https://www.dolibarr.org/forum/u/Plows)\
**Post date:** [April 7, 2023, 10:52am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/8 "2023-04-07T10:52:18Z")

</div>

i do not believe what happend

 ![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/b/b47afc025d5dbcad4ac225d4566d64ad94192a6a.png)

My Problem disappeared while removing not needed scopes, now it is collecting mails.

---

<div class="post-metadata">

**Author:** ![JanGekheid](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@JanGekheid](https://www.dolibarr.org/forum/u/JanGekheid)\
**Post date:** [May 3, 2023, 12:04pm UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/10 "2023-05-03T12:04:48Z")

</div>

Hi Plows,

Great that you got this to work. I used your setup to get it to work for me too (using dolibarr 17.01). It seems I’m almost there. OAuth2 works. Token is automatically renewed. That seems all good.

However, when I try the “Test collection” (from the module setup page) it redirects me to this page:  
https://{my website}/admin/emailcollector\_card.php?id=6&action=collecttest&token={myToken}

This throws a http 500 “{myWebsite} is currently unable to handle this request.” error. Have you noticed this as well? Does the test option work for you?

---

<div class="post-metadata">

**Author:** ![Plows](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/plows/32/5660_2.png) [@Plows](https://www.dolibarr.org/forum/u/Plows)\
**Post date:** [May 4, 2023, 5:49am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/11 "2023-05-04T05:49:33Z")

</div>

Hi,  
i have the same redirection but no error, was the collector working before?

---

<div class="post-metadata">

**Author:** ![sitcomputers](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@sitcomputers](https://www.dolibarr.org/forum/u/sitcomputers)\
**Post date:** [June 21, 2023, 11:34am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/12 "2023-06-21T11:34:18Z")

</div>

Hi guys,

i followed your instructions but it wont work.  
If i try to send mails i get this error:  
Fehler beim Senden der E-Mail (Absender=Robert Steinbacher [steinbacher@sit-edv.de](mailto:steinbacher@sit-edv.de), Empfänger=steinbacher@sit-edv.de)  
Error [120]: Ran into problems sending Mail. Response: 535 5.7.3 Authentication unsuccessful [[XXXXXX.OUTLOOK.COM](http://XXXXXX.OUTLOOK.COM) 2023-06-21T11:29:03.190Z 08DB71B1AD081F9E] Error [130]: Error when asking for AUTH XOAUTH2 Error [130]: Invalid Authentication Credentials.

When i try to receive mails theres is no error but when i count mails in source this error appears:  
failed to refresh access token

if anyboy has it working and when how?

here is my config

 ![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/4/41814d7029fbca3347aeb57e91f10603e4148462.png)

---

<div class="post-metadata">

**Author:** ![sitcomputers](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@sitcomputers](https://www.dolibarr.org/forum/u/sitcomputers)\
**Post date:** [June 21, 2023, 11:34am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/13 "2023-06-21T11:34:58Z")

</div>

![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/2/2d4d9f523e427ed46c28182db9c03edfcd4c013e.png)

---

<div class="post-metadata">

**Author:** ![JanGekheid](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/j/cc9497/32.png) [@JanGekheid](https://www.dolibarr.org/forum/u/JanGekheid)\
**Post date:** [June 21, 2023, 11:46am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/14 "2023-06-21T11:46:55Z")

</div>

Apologies for my delayed response. I’m only working on this for 1 day a week and had to work on other stuff first.

No, it hasn’t worked before yet. What I don’t understand is that if I navigate to the page itself it exists and there is no error.

By the way, I noticed in the file htdocs\>includes\>OAuth\>OAuth2\>Service\>Microsoft.php that there are some SCOPE constants with the wrong name: the name starts with SOCPE instead of SCOPE. This is the case for the constants IMAP\_ACCESSASUSERALL, SMTPSEND, USERREAD, MAILREAD, and MAILSEND. In the ServiceFactory it checks the provided scopes against the defined scopes, so the scopes above will never be resolved, correct?

---

<div class="post-metadata">

**Author:** ![FAdo84](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@FAdo84](https://www.dolibarr.org/forum/u/FAdo84)\
**Post date:** [June 21, 2023, 12:38pm UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/15 "2023-06-21T12:38:41Z")

</div>

> [@sitcomputers](#):
>
> If i try to send mails i get this error:

If you are not able to send but only receive you have to follow this step:

> **[Setup EMails](https://wiki.dolibarr.org/index.php?title=Setup_EMails#Outlook_.2F_Office365_.2F_Exchange_server_.28with_mode_relay.29)**
>
> Online wiki documentation of Dolibar ERP CRM software

---

<div class="post-metadata">

**Author:** ![sitcomputers](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@sitcomputers](https://www.dolibarr.org/forum/u/sitcomputers)\
**Post date:** [June 21, 2023, 3:11pm UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/16 "2023-06-21T15:11:04Z")

</div>

Sending is now working very fine. just receiving isnt working. i corrected the SCOPE in htdocs\>includes\>OAuth\>OAuth2\>Service\>Microsoft.php as mentioned  
I am a little confused because i get an error in the collector when i check the mails in folder. it returns: Failed to refresh access token:

---

<div class="post-metadata">

**Author:** ![Plows](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/plows/32/5660_2.png) [@Plows](https://www.dolibarr.org/forum/u/Plows)\
**Post date:** [June 23, 2023, 9:44am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/17 "2023-06-23T09:44:24Z")

</div>

Hi,  
i have a different Configuration

 ![image](https://www.dolibarr.org/forum/uploads/dolibarrorg/original/2X/5/5a966b2a0cd1ae3be788bc0b2f6da4c180c1b9d6.png)

---

<div class="post-metadata">

**Author:** ![FAdo84](https://www.dolibarr.org/forum/letter_avatar_proxy/v4/letter/f/59ef9b/32.png) [@FAdo84](https://www.dolibarr.org/forum/u/FAdo84)\
**Post date:** [June 23, 2023, 10:57am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/18 "2023-06-23T10:57:55Z")

</div>

Hi,  
the scope or socpe is not the problem. Please follow my “tutorial” and please check the scopes inside Microsoft Azure

---

<div class="post-metadata">

**Author:** ![Plows](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/plows/32/5660_2.png) [@Plows](https://www.dolibarr.org/forum/u/Plows)\
**Post date:** [November 1, 2023, 12:39pm UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/19 "2023-11-01T12:39:14Z")

</div>

Hi Jan,  
i have the same Problem now, did you solve your http 500 error?

---

<div class="post-metadata">

**Author:** ![Plows](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/plows/32/5660_2.png) [@Plows](https://www.dolibarr.org/forum/u/Plows)\
**Post date:** [November 5, 2023, 11:05am UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/20 "2023-11-05T11:05:56Z")

</div>

Hi,  
i believe there are some PHP problems, this morning i installed the beta 19.0.0 (XAMPP - PHP 8.1.17) as a test version, now the mails are coming in again (some PHP Warnings), as before (Version 17.0.1 with Ubuntu PHP 7.4.33).  
Sending was in all Versions never a Problem

---

<div class="post-metadata">

**Author:** ![eldy](https://www.dolibarr.org/forum/user_avatar/www.dolibarr.org/eldy/32/12_2.png) [@eldy](https://www.dolibarr.org/forum/u/eldy)\
**Post date:** [March 1, 2024, 1:04pm UTC](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437/21 "2024-03-01T13:04:45Z")

</div>

@Plows and @FAdo84 Can you paste a screenshot of the setup you have for your the scopes in OAuth entry setup with the v19 ?  
Do you use a different Oauth entry for sending/smtp ? If yes, can you also paste the one you have that work correctly with v19 ?

[Next page](https://www.dolibarr.org/forum/t/oauth-office-365-and-email-collector/23437.md?page=2)
