Configuring JSM Mail Handlers: IMAP/POP Required for OAuth 2.0
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Configuring a JSM Mail Handler for a Service project via Project Settings > Email Request fails with the error "We could not connect to your mail server" while using authorize with Oauth 2.0.
Solution
Environment
Jira Service Management 4.10.0 and higher
Error when authorizing with Oauth 2.0
An Oauth 2.0 integration was configured in ⚙ > System > Oauth 2.0, with the same scopes as the ones mentioned in Integrating with Oauth 2.0, and the connection test was successful
When trying to configure a JSM Mail Handler via the page Project Settings > Email Request:
Either of the 2 following errors is thrown when clicking the authorize button with the Oauth 2.0 authentication.
Error 1
1 2
We couldn't connect to your mail server 'JIRA couldn't open the folder 'inbox' at outlook.office365.com. Check and make sure the folder name is correct and try again.'
Error 2
1 2
We couldn't connect to your mail server Here's the error we received: OAuth token not defined for connection. OAuth Authorisation required.
Note that the same error is thrown thrown when clicking the update button with the basic authentication
The following errors are thrown in the logs
Error thrown in the Jira application logs
1 2 3 4
2021-11-10 14:50:57,000+0000 http-nio-8080-exec-16 ERROR testuser 890x5726803x3 ygh5pa XXX.XX.X.XXX /rest/servicedesk/1/servicedesk/VYRGLOGTB/incomingemail/oauth/validateandsaveflow/f6c632f6-82c3-43d8-a821-447e47a32948 [c.a.s.i.rest.emailchannel.EmailChannelResource] Failed to validate and save token: jep.mail.connection.verifier.missing.folder.error : 'JIRA couldn't open the folder 'inbox' at outlook.office365.com. Check and make sure the folder name is correct and try again.'
Error thrown in the Jira incoming mail logs
1 2 3 4 5 6 7 8 9
2021-11-10 14:51:00,802+0000 ERROR [] http-nio-8080-exec-12 testuser 891x5727070x4 ygh5pa XXX.XX.X.XXX/rest/servicedesk/1/servicedesk/admin/email/test Unable to connect to the server at outlook.office365.com due to the following exception: com.atlassian.jira.internal.mail.processor.errors.MailConnectionException: OAuth token not defined for connection. OAuth Authorisation required. at com.atlassian.jira.internal.mail.processor.feature.channel.connectionverifier.DefaultChannelConnectionVerifier.verifyConnectionDefinition(DefaultChannelConnectionVerifier.java:87) [?:?] at com.atlassian.jira.internal.mail.processor.feature.channel.connectionverifier.DefaultChannelConnectionVerifier.verifyConnectionDefinition(DefaultChannelConnectionVerifier.java:69) [?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [?:1.8.0_292] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [?:1.8.0_292] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [?:1.8.0_292] at java.lang.reflect.Method.invoke(Method.java:498) [?:1.8.0_292]
When trying to configure a Jira Mail Handler with the same mailbox time from the page ⚙ > System > Incoming Mail using the Oauth 2.0 authentication, the following happens:
Adding a Mail Server is possible, and the authorize button and the test connection button both give successful results, making it look like the mail server will work well in Jira:
However, after adding a Mail Handler linked to the Mail Server, we can see that the test of the mail handler fails with the following error, making the mail handler un-usable:
1 2 3 4
javax.mail.MessagingException: * BYE Jakarta Mail Exception: java.net.SocketTimeoutException: Read timed out while connecting to host "outlook.office365.com" as user "null" via protocol "SECURE_IMAP", caused by: com.sun.mail.iap.ConnectionException: * BYE Jakarta Mail Exception: java.net.SocketTimeoutException: Read timed out
The cause is IMAP (or POP, depending on which protocol is used to configure the mail server in Jira) is disabled for the mailbox.
Enabling IMAP or POP in Exchange or O365
If a Microsoft Exchange mailbox is used, enable IMAP (or POP) for the mailbox, by following the instructions in Enable or disable POP3 or IMAP4 access to mailboxes in Exchange Server.
If an Office 365 mailbox is used, enable IMAP (or POP) for the mailbox, by following the instructions in Enable or disable POP3 or IMAP4 access for a user in Exchange Online. See screenshot below for reference:
Was this helpful?