0 votes

Hello,

I had been using OAuth 2.0 Imap.LoginOAUTH2(string user, string accessToken) for Gmail for the past 2 years or so. I had been using "mail.google.com" scope while requesting for the access & refresh token in the first user email setup.

As the scope "mail.google.com" is a restricted scope, during the app verification in google, i was instructed to use "gmail.send" and "gmail.readonly" scope as that would be sufficient for my app. My app only sends the email and retrieves the email of the user. No delete/move action is performed.

I used the suggested scope, I was able to set up the email using OAuth, requesting only for the said scopes. Check Scopes HERE

But, when I try to send email using the token that I just got, i get the following error :

"Username and Password not accepted. For more information, go to https://support.google.com/mail/?p=BadCredentials u20-20020a056a00099400b006da76842a66sm4965827pfg.85 - gsmtp"

The method in question is following :

// server="smtp.gmail.com",token is the one OAuth provided
public Smtp NewConnection(string server, string token, string useremail, string serviceProvider)
{
    var smtp = new Smtp();
    smtp.ConnectSSL(server);
    smtp.LoginOAUTH2(useremail, token);
    return smtp;
}

The same code works flawlessly, if "mail.google.com" scope is used, however since that scope is restricted, I cannot request that scope. Using the minimal scope "gmail.send" and "gmail.readonly" has raised these issues.

I would really appreciate you rhelp in this matter. Any guidance to the right solution would be much appreciated.

Thank You

by (400 points)

1 Answer

0 votes

Gmail requires https://mail.google.com/ scope to be used for IMAP.

Other scopes will simply not work, even if you perform only read operations.

by (297k points)
...