-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled Exception: Incorrect username / password / credentials #127
Comments
Can you please try if the same credentials work in another mailing app. In any case I would recommend using: |
I'll try to improve the documentation. |
I am using Google APIs and created a service account. I copied service account content into a Future<AccessCredentials> getAccessToken() async {
var accountCredentials = ServiceAccountCredentials.fromJson({
"private_key_id": CLIENT_JSON["private_key_id"],
"private_key": CLIENT_JSON["private_key"],
"client_email": CLIENT_JSON["client_email"],
"client_id": CLIENT_JSON['client_id'],
"type": "service_account"
});
AccessCredentials accessCredentials;
final client = http.Client();
try {
accessCredentials = await obtainAccessCredentialsViaServiceAccount(
accountCredentials, ["https://mail.google.com/"], client);
print("[EMAIL_SERVICE] Access Token Fetched");
} on Exception catch (err) {
print("[EMAIL_SERVICE] Error in fetching access token. Error: $err");
}
client.close();
return accessCredentials;
}
Future<void> sendEmailFromConfibuddy({
@required String receiverEmail,
@required String subject,
@required String body,
}) async {
final credentials = await getAccessToken();
if (credentials == null) {
print("[EMAIL_SERVICE] Credentials are null.");
return;
}
final smtpServer = gmailSaslXoauth2(
CLIENT_JSON["client_email"], credentials.accessToken.data);
final message = Message()
..from = Address(CLIENT_JSON["client_email"], 'Confibuddy')
..recipients.add("[email protected]")
..subject = subject
..html = body;
try {
final sendReport = await send(message, smtpServer);
print('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
print('Message not sent.');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
}
}
} Right now, the access token is generating successfully but I am not sure, about using |
I don't see any obvious mistakes in your code. Please enable debug log output:
This will hopefully give a better error message (the response from google) |
I've deleted your comment as it included your mail address and oauth token. That looks good. |
Could you please try version 5
It fixed a lot of bugs and probably also yours.
Regards
Christian
…On Wed, 17 Mar 2021, 15:42 Prashant Joshi, ***@***.***> wrote:
Thanks, man, I totally forgot about the email and token. And no, I am not
getting any message indicating acceptance of my OAuth. I next message I am
getting is Message not sent which is from try..catch block.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#127 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACZDOJRK7VYMSDMNL656VDTEC5ULANCNFSM4KAPEBQQ>
.
|
I am facing the the same issue ... looks like the token is generated and valid, but credentials fails when sending |
Please enable debug output: Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
}); Hide your token and post the output. |
Hey, I'm getting this error too @close2 My code: main(List<String> rawArgs) async {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
print('${rec.level.name}: ${rec.time}: ${rec.message}');
});
String username = '[email protected]';
Map<String, String> env = Platform.environment;
ServiceAccountCredentials serviceAccCreds = ServiceAccountCredentials.fromJson(env['AAC_GS']);
final client = http.Client();
AccessCredentials credentials = await obtainAccessCredentialsViaServiceAccount(serviceAccCreds, scopes, client);
client.close();
final oauth2token = base64Encode(
utf8.encode('user=$username\x01auth=${credentials.accessToken.type} ${credentials.accessToken.data}\x01\x01'));
// I also tried (username, credentials.accessToken.data) here like the guy above, same error
final smtp = gmailSaslXoauth2(username, oauth2token);
final message = Message()
..from = Address(username, 'Service acct')
..recipients.add('[email protected]')
..subject = 'this better work'
..text = 'asdf';
try {
final sendReport = await send(message, smtp);
print('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
print('Message not sent. $e');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
}
} My logs:
btw my accessToken.data seems to have this very long string of 'Li4uLi4uLi4uLi4u' in it (maybe 100x) - is this normal? If there's anything else you need from me, let me know. |
I can't easily reproduce your problem. Could you please verify that your token is correct. It seems really odd to me, that you have those The googleapis_auth library and XOAuth2 is not really my speciality. |
alexobviously I'm having the same issue. Did you manage to resolve it? |
Anyone who has found a fix for this? |
@abelokon0711 @vanlooverenkoen this guy got the same issue at 09:35 link |
Another workaround is to first enable 2-factor authentication and then create an app password. |
My Username and password are correct. And also I enable Access to less secure app feature on gmail. How to fix this issue?
The text was updated successfully, but these errors were encountered: