OAuth20 authentication is failing for Gmail.
Below is the smtpException I am getting:
Rebex.Net.SmtpException: OAuth failed: OAuth authentication failed due to Invalid token. Code -2147184118
For gmail, I'd given full scope - mail.google.com/ but nothing is mentioned for outlook. This is what I've given as scope for outlook - openid+offline_access+profile+https:%2f%2foutlook.office.com%2fmail.send
Below is the code snippet:
try{
Smtp client = new Smtp();
client.Connect("smtp-mail.outlook.com", SslMode.Explicit);
// prepare token
string pattern = string.Format("user={0}{1}auth=Bearer {2}{1}{1}", userEmailId, '\x1', accessToken);
string token = Convert.ToBase64String(Encoding.ASCII.GetBytes(pattern));
client.Login(token, SmtpAuthentication.OAuth20);
}
catch(SmtpException ex)
{}
}
Kindly let me know if there is anything that I'm doing wrong here. I could make this work with Gmail. I've also tried to use IMAP instead of SMTP for outlook but no result.
Regards
Mrinal