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 -http://blog.rebex.net/howto-authenticate-gmail-rebex-oauth/. I'm trying to setup an outlook email account. I'm successfully able to get the access token.

var client= new Smtp();
client.Connect("smtp-mail.outlook.com", SslMode.Explicit);
client.Login(token,SmtpAuthentication.OAuth20);

token here is base64 -encoded string , just like you've shown for gmail. ( Ref - https://msdn.microsoft.com/en-IN/library/dn440163.aspx )

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 - smtp.live.com as well but no luck.

I've passed these scopes for authentication - https://outlook.office.com/Mail.ReadWrite https://outlook.office.com/Mail.Send 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!

Applies to: Rebex Secure Mail
commented Nov 17, 2016 by Tomas Knopp (58,580 points)
SMTP details for the live.com SMTP server is:
"smtp-mail.outlook.com"
port = 587
explicit TLS

with Rebex SMTP just write the following:
           
            var smtp = new Smtp();
            smtp.Connect("smtp-mail.outlook.com", SslMode.Explicit);
commented Nov 17, 2016 by Tomas Knopp (58,580 points)
As to the Oauth2.0 authentication to outlook.com/live.com servers.
I've found the following tutorial https://msdn.microsoft.com/en-us/library/dn440163.aspx

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 https://msdn.microsoft.com/en-us/library/hh243646.aspx
commented Nov 18, 2016 by MrinalGrover (200 points)
Thanks Tomas. There were 2 issues :
I was calling new end point(https://login.microsoftonline.com/common/oauth2/v2.0/authorize) with the mentioned scopes for access token. I'd to use deprecated Live Connect APIs(login.live.com) and need to pass wl.imap scope for smtp access.
commented Nov 18, 2016 by Lukas Matyska (37,860 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,580 points)

1 Answer

0 votes
answered Nov 21, 2016 by Tomas Knopp (58,580 points)

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

See http://forum.rebex.net/6674/authenticate-yahoo-and-outlook-com-email-servers-with-oauth for more details.

...