freescout-help-desk / freescout

FreeScout — Free self-hosted help desk & shared mailbox (Zendesk / Help Scout alternative)
https://freescout.net
GNU Affero General Public License v3.0
3.06k stars 503 forks source link

Unable to fetch IMAP folders from Exchange Online using OAuth #2264

Closed salimnassim closed 2 years ago

salimnassim commented 2 years ago

We're having issues with fetching IMAP folders from a Exchange Online mailbox.

The mailbox is a regular user and not a shared mailbox, and it has a valid Exchange license.

OAuth has been configured correctly according to https://github.com/freescout-helpdesk/freescout/wiki/Connect-FreeScout-to-Microsoft-365-Exchange-via-OAuth and the auth flow works.

When I try to retrieve IMAP folders I get the following message "Connected, but no IMAP folders found" and IMAP folders field will be populated with the default "INBOX". Clicking "check connection" after saving displays the following error "Could not get mailbox folder: INBOX". Due to this problem emails wont be retrieved from the mailbox.

App version is 1.8.26 and the system status page does not display any errors.

Any ideas? Thanks

freescout-helpdesk commented 2 years ago

It looks like something is going on in MS365 system. Some people are receiving "connection setup failed" error. You can't get IMAP folders...

freescout-helpdesk commented 2 years ago

https://github.com/freescout-helpdesk/freescout/issues/2248 https://github.com/freescout-helpdesk/freescout/issues/2232

freescout-helpdesk commented 2 years ago

What happens when you click "Check Connection" button in your mailbox?

freescout-helpdesk commented 2 years ago

@salimnassim Does the MS365 user you are using to connect have a mailbox in MS365 and a license allowing to access it (try to open https://outlook.office365.com/mail/)?

salimnassim commented 2 years ago

What happens when you click "Check Connection" button in your mailbox?

I get a red popup notification which says "Could not get mailbox folder: INBOX"

@salimnassim Does the MS365 user you are using to connect have a mailbox in MS365 and a license allowing to access it (try to open https://outlook.office365.com/mail/)?

The user account has a working mailbox and I can access it directly through the PWA and Outlook.

freescout-helpdesk commented 2 years ago

Try to contact MS365 support and ask why INBOX folder is not available via OAuth IMAP. Maybe they added some restrictions...

salimnassim commented 2 years ago

Try to contact MS365 support and ask why INBOX folder is not available via OAuth IMAP. Maybe they added some restrictions...

I have created a ticket for Microsoft regarding this issue. I will update this ticket in case they have a solution.

salimnassim commented 2 years ago

Apparently there's an ongoing issue with accessing mailbox via IMAP and the problem affects OAuth/Graph as well. This is the reply from them in case anybody else is having the same issue.

I've confirmed that you're affected by a service incident causing IMAP issue. We understood that resolving this issue is very important for your business. Rest assured that our Microsoft engineers are continuously working to resolve this issue.

Here's the incident you're affected with:

Sep 15, 2022, 11:06:42 PM
Exchange Online
EX431096
Users may have been unable to connect to their mailboxes via the Outlook desktop app with IMAP.
freescout-helpdesk commented 2 years ago

Thanks for sharing the info.

freescout-helpdesk commented 2 years ago

We've added a notice to https://github.com/freescout-helpdesk/freescout/wiki/Connect-FreeScout-to-Microsoft-365-Exchange-via-oAuth#fetching-emails

salimnassim commented 2 years ago

After Microsoft reported that the issue I referenced to is fixed the problem with retrieving folders still persists. I have tested accessing the same mailbox via IMAP using other software such as Thunderbird and it works flawlessly. Is this an issue with Webklex/php-imap perhaps? Any ideas how to debug this further? Thanks

freescout-helpdesk commented 2 years ago

It seems you are the only one receiving "Connected, but no IMAP folders found" error so far. You need a developer who can debug Webklex/php-imap.

jeliasson commented 2 years ago

It seems you are the only one receiving "Connected, but no IMAP folders found" error so far. You need a developer who can debug Webklex/php-imap.

We also seem to have this issue where we get "Connected, but no IMAP folders found". We will continue to troubleshoot on our side, but would love some help on what that could be.

freescout-helpdesk commented 2 years ago

See "Debugging OAuth Emails Fetching": https://github.com/freescout-helpdesk/freescout/wiki/Connect-FreeScout-to-Microsoft-365-Exchange-via-OAuth#debugging-oauth-emails-fetching

pathab commented 2 years ago

We also had connection issues to IMAP folder of all mailboxes today. All mailboxes are Microsoft 365 Exchange mailboxes. We were able to resolve the connection issues by switching the connections to OAuth. Thanks for the instructions! (https://github.com/freescout-helpdesk/freescout/wiki/Connect-FreeScout-to-Microsoft-365-Exchange-via-OAuth)

Unfortunately, after that, we were unable to retrieve IMAP folders for all mailboxes.

The problem is that we use the SAML SSO module. So the personal account is always logged in. When we clicked "Connect", the authentication was done with the personal account and not with the account of the mailbox. grafik

The solution to solve this problem was:

  1. disconnect again
  2. open Freescout in a private window in the browser
  3. login as admin with the URL: yourfreescouturl.com/login?saml=0
  4. connect again to the "Microsoft Exchange" under connection settings
  5. authenticate with the user of the mailbox
  6. done :-)

I hope this helps you.

Edit: The problem will probably also exist independently of the "SAML SSO" module. Of course, this may also be due to the SSO of office.com, which triggers authentication with the personal account and not with the respective mailbox user.

salimnassim commented 2 years ago

Logging in with the mailbox user solved this issue for us, and we are able to retrieve the IMAP folders. My assumption was that the system would be smart enough to use the correct mailbox via OAuth but this was not the case.

Thanks for the workaround @pathab !

freescout-helpdesk commented 2 years ago

Good to know.

PebiValeur commented 2 years ago

I'm still experiencing this issue regarding connection setup failed. Although there is a quick fix, where you click check connection twice. 1st time it comes with an error message "Connection setup failed" 2nd time it comes with "Connection established", and then again we are able to recieve mails for about 2 hours before it cuts the connection once more.

We are currently running an older version, due to the fact we are running it on a live enviroment. Aswell as the fear of losing some of the settings.

Right now the version we have running is 1.8.12. could that have anything to do with it? Please let me know if there's anything else you need from me

thanks in advance!

justinipg commented 1 year ago

i'm getting an error from Microsoft saying the following.

AADSTS50011: The redirect URI 'https://servicedesk.XXX.net.au/mailbox/oauth' specified in the request does not match the redirect URIs configured for the application '288c5f41-5671-4726-9ece-XXXXXX'. Make sure the redirect URI sent in the request matches one added to your application in the Azure portal. Navigate to https://aka.ms/redirectUriMismatchError to learn more about how to fix this.

when i go to the /mailbox/oath address all i receive is a "Sorry, the page you are looking for could not be found"

mateit-cloudware commented 1 year ago

HI There, we have setup the Azure AD Connection to fetch mail. But are facing the following issue:

image

We cleared the cache and also connected again. Folders where fetched perfectly all premissions are set in Azure. So still the same issue. Can you please help?

We have installed Freescout via Cloudron

freescout-helpdesk commented 1 year ago

@mateit-cloudware Create a new separate issue. Also specify where and at what moment are you getting this error.

mateit-cloudware commented 1 year ago

@freescout-helpdesk: thank you. Done https://github.com/freescout-helpdesk/freescout/issues/3503