Error while Configuring SMTP and IMAP email accounts with Microsoft Office365 using OAuth2

Jayant Pandit
Giga Expert

We are following below document provided by SNOW,

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0816072

IMAP is working fine,

SMTP test connection showing below error.

"Connection Failed
Email sender connection invalid.: Cannot connect to SMTP server: smtp.office365.com"
 
Appreciate your inputs.
 
Thanks
Jayant
1 ACCEPTED SOLUTION

@Nguyen Minh Tam , @Kushal Bahirwani , @Jerry Wong 

Hello Everyone,

I managed to solve this on my own,

below are the steps.

 

Configure your OAuth Profile in Application Registry, Add Entity Scopes.

Create 2 Email Accounts, one for IMAP and another for SMTP.

When you click on "Authorize Email Account" .

Make sure that you are signed in as same email account in the browser that you want to configure for email sending and receiving.

 

For example.

My email ID is 'jayantcpandit@gmail.com'

Email that I want to configure is 'example@example.com'

In this case, I need to sign in to the browser with 'example@example.com' where I click on "Authorize Email Account", not with my 'jayantcpandit@gmail.com'

With this way, it will make sure that you are using correct account to authorize.

 

Hope this helps.

Please mark this helpful, if solves your issue.

 

Thanks

Jayant

View solution in original post

28 REPLIES 28

Can you please share the logs ? 

Here is the log : 

Cannot connect to SMTP server: smtp.office365.com, as: ********@crelan.be, message: Could not connect to SMTP host: smtp.office365.com, port: 587: javax.mail.MessagingException: Could not connect to SMTP host: smtp.office365.com, port: 587;
nested exception is:
javax.net.ssl.SSLException: Unsupported or unrecognized SSL message: com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2212)
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:722)
javax.mail.Service.connect(Service.java:342)
com.glide.email.oauth2.smtp.SMTPOAuth2Connection.connectTransport(SMTPOAuth2Connection.java:61)
com.glide.email.oauth2.smtp.SMTPOAuth2Connection.<init>(SMTPOAuth2Connection.java:20)
com.glide.email.oauth2.smtp.SMTPOAuth2Sender.initializeOAuth2(SMTPOAuth2Sender.java:54)
com.glide.email.oauth2.smtp.SMTPOAuth2Sender.initialize(SMTPOAuth2Sender.java:38)
com.glide.notification.outbound.SMTPSender.<init>(SMTPSender.java:67)
com.glide.email.oauth2.smtp.SMTPOAuth2Sender.<init>(SMTPOAuth2Sender.java:19)
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
com.glide.notification.EmailHandler.getExtendedEmailHandler(EmailHandler.java:99)
com.glide.notification.EmailHandler.getExtendedEmailSender(EmailHandler.java:40)
com.glide.notification.outbound.EmailSender.getEmailSender(EmailSender.java:71)
com.glide.notification.outbound.EmailSender.getEmailSender(EmailSender.java:89)
com.glide.notification.glidefacade.EmailSenderProxyImpl.<init>(EmailSenderProxyImpl.java:10)
com.glide.notification.glidefacade.EmailSenderProxyImpl$$FastClassByGuice$$2c3c419.newInstance(<generated>)
com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:60)
com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)
com.google.inject.assistedinject.FactoryProvider2.invoke(FactoryProvider2.java:632)
com.sun.proxy.$Proxy45.build(Unknown Source)
com.glide.job.SMTPSenderJob.chunkedSend(SMTPSenderJob.java:181)
com.glide.job.SMTPSenderJob.execute(SMTPSenderJob.java:160)
com.glide.schedule.JobExecutor.lambda$executeJob$0(JobExecutor.java:140)
com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:143)
com.glide.schedule.JobExecutor.execute(JobExecutor.java:127)
com.glide.schedule_v2.SchedulerWorkerThread.executeJob(SchedulerWorkerThread.java:338)
com.glide.schedule_v2.SchedulerWorkerThread.lambda$process$0(SchedulerWorkerThread.java:225)
com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35)
com.glide.schedule_v2.SchedulerWorkerThread.process(SchedulerWorkerThread.java:225)
com.glide.schedule_v2.SchedulerWorkerThread.run(SchedulerWorkerThread.java:101)

Hi Laurent,

Please check with Office 365 guy who can help you with SSL settings. Confirm the port number , and SSL protocol they are using from their end. 

Most of the issues in this integration I faced are from the Office end only , so we need to coordinate from their end.

 

Please mark this helpful, if solves your issue.

Dear,

We have checked with the Azure admin, and the user is properly authenticated. We get the token in ServiceNow. 

When we try to test connection, nothing appears at Azure, meaning that the request is blocked before reaching Azure.