Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET IMAP

 AfterLogic Forum : MailBee.NET IMAP
Subject Topic: SaslOAuth2 fails with NO AUTHETICATE Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
phlexss
Newbie
Newbie


Joined: 05 September 2022
Location: Netherlands
Online Status: Offline
Posts: 6
Posted: 06 September 2022 at 3:14am | IP Logged Quote phlexss

Hi,

I try to use IMAP to read emails from Office365.

I can successfully request a token and I use the token in:

myImap.Login(Nothing, my_token, AuthenticationMethods.SaslOAuth2, AuthenticationOptions.None, Nothing)

But then I get:

The server responded: MBN00000002 NO AUTHENTICATE failed.

I read that Office365 doesn't support using the token for IMAP....but how to get this to work then?

I read that MS supports sending the following command in imap to get authenticated, but I can't do this with the mailbee imap control?:

AUTHENTICATE XOAUTH2 <base64 string in XOAUTH2 format>

In another post someone mentioned they got "credential flow" to work to read messages, but I don't know how to do this.

In short:

how can I use the mailbee controls to read/send emails using an Office365 account and oauth2?

I have found and read a lot of info about this...but so far it's all quite unclear and I have not been successfull in reading my Office365 mailbox.

Any help is appreciated!
Back to Top View phlexss's Profile Search for other posts by phlexss
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2182
Posted: 06 September 2022 at 3:27am | IP Logged Quote Alex

Hi,

They (Office 365 team) are changing things all the time. Sometimes it works :)

This code works for me.
Code:

using Microsoft.Identity.Client;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using MailBee;
using MailBee.Pop3Mail;
using MailBee.ImapMail;
using MailBee.SmtpMail;
using Newtonsoft.Json;

....

string clientId = "...";
string tenantId = "...";
string clientSecret = "...";
string userEmail = "...";
string[] scopes = { "https://outlook.office365.com/.default" };
IConfidentialClientApplication confidentalApp = ConfidentialClientApplicationBuilder.Create(clientId).WithTenantId(tenantId).WithClientSecret(clientSecret).Build();
AuthenticationResult result = await confidentalApp.AcquireTokenForClient(scopes).ExecuteAsync();
string xOAuthKey = OAuth2.GetXOAuthKeyStatic(userEmail, accessToken);
Imap imap = new Imap();
imap.Connect("outlook.office365.com", 993);
imap.Login(null, xOAuthKey, AuthenticationMethods.SaslOAuth2, AuthenticationOptions.None, null);
imap.Disconnect();


The trickiest part is setting all permissions in Office 365. It's not the scope of MailBee techsupport as it's configuring third-party provider and it has nothing special for MailBee, it's all the same for any IMAP client which wants to connect to Office 365 IMAP via OAuth 2.0.

We can send you the manual which we found working if you you leave a ticket in Helpdesk but again, it's not official. Only MS can be authoritative techsupport on the subject of generating OAuth2 tokens for their service.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
phlexss
Newbie
Newbie


Joined: 05 September 2022
Location: Netherlands
Online Status: Offline
Posts: 6
Posted: 06 September 2022 at 4:08am | IP Logged Quote phlexss

Hi Alex,

the problem is not in getting the token....I can get a token and this has the following format:

user=user@domain.com auth=Bearer hflkjdsapouyfeofifewirqep.....

I think this is a correct token is it not?

But then if I use this token in imap I get the "MBN00000002 NO AUTHENTICATE failed" error.

Maybe the problem is a setting in Office365? Do you maybe have any info on that?

Thanks!
Back to Top View phlexss's Profile Search for other posts by phlexss
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2182
Posted: 06 September 2022 at 4:36am | IP Logged Quote Alex

The problem is always getting the token. A working token, I mean. As I mentioned in the previous post, via Helpdesk we can share an unofficial guide which may help you get the correct token (which is mainly the question of configuring lots of things in Office 365).

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
phlexss
Newbie
Newbie


Joined: 05 September 2022
Location: Netherlands
Online Status: Offline
Posts: 6
Posted: 06 September 2022 at 4:40am | IP Logged Quote phlexss

Hi Alex,

Do you mean to say that the token I get is not a correct token?

Is the format ok:

user=user@domain.com auth=Bearer hflkjdsapouyfeofifewirqep.....

(ofcourse in reality it looks a little different)

I can understand that the token itself may not be correct depending on API permissions....but the procedure to request the token works fine I think.

How can I get this "unofficial guide"?
Back to Top View phlexss's Profile Search for other posts by phlexss
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 5931
Posted: 06 September 2022 at 4:41am | IP Logged Quote Igor

Please open a ticket at:

https://s.afterlogic.com/helpdesk/

Thank you.

--
Regards,
Igor, Afterlogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide