Help with Rebex Setup for OAuth 2 SMTP Client

+1 vote
asked Nov 17, 2016 by MrinalGrover (200 points)
retagged Nov 17, 2016 by Tomas Knopp

I've followed the sample given here - I'm trying to setup an outlook email account. I'm successfully able to get the access token.

var client= new Smtp();
client.Connect("", SslMode.Explicit);

token here is base64 -encoded string , just like you've shown for gmail. ( Ref - )

Login statement throws this exception -
{Rebex.Net.SmtpException: OAuth failed: OAuth authentication failed due to Invalid token. Code -2147184118 (535).
at Rebex.Net.Smtp.JRR(String T, String R, SmtpAuthentication J, GssApiProvider C)
at Rebex.Net.Smtp.JG(String T, String R, SmtpAuthentication J)
at Rebex.Net.Smtp.Login(String token, SmtpAuthentication method)

Please note that I'm trying to do this for @outlook account and not office 365. I've tried this with - as well but no luck.

I've passed these scopes for authentication - openid profile.

Please let me know if I'm missing anything here?

Also, If you could also provide information on the following things -
1. Is there a future plan to provide support for Gmail REST API , Outlook REST API to send mails
2. Giving SSL.Implicit for Outlook doesn't work. Any reason for it?

Any inputs are appreciated. Thank you!

commented Nov 17, 2016 by Tomas Knopp (58,890 points)
SMTP details for the SMTP server is:
port = 587
explicit TLS

with Rebex SMTP just write the following:
            var smtp = new Smtp();
            smtp.Connect("", SslMode.Explicit);
commented Nov 17, 2016 by Tomas Knopp (58,890 points)
As to the Oauth2.0 authentication to servers.
I've found the following tutorial

According to the above tutorial, the scopes that you said (Mail.ReadWrite and Mail.Send)you requested does not seem to be supported at all. Maybe this is the problem? See possible scopes and permissions at
commented Nov 18, 2016 by MrinalGrover (200 points)
Thanks Tomas. There were 2 issues :
I was calling new end point( with the mentioned scopes for access token. I'd to use deprecated Live Connect APIs( and need to pass wl.imap scope for smtp access.
commented Nov 18, 2016 by Lukas Matyska (61,230 points)
If I understand it correctly. You were able to make it working?
commented Nov 21, 2016 by MrinalGrover (200 points)
Yes, this is working perfectly fine with outlook. Thanks.
commented Nov 21, 2016 by Tomas Knopp (58,890 points)

1 Answer

0 votes
answered Nov 21, 2016 by Tomas Knopp (58,890 points)
edited Mar 24, 2021 by Lukas Pokorny

I have summarized the findings about getting the OAuth 2.0 access tokens with Yahoo and mail servers.

See for more details.

Update: We published a blog post that describes how to login with OAuth 2.0 to Office365 with Rebex Secure Mail, and another one that describes how to register application for with appropriate permissions in Azure.