Incorrect username or password or credentials sending email with Flutter

Viewed 35

hello i'm new with flutter . i have problem in sent an email with flutter . i'm using the plugin mailer to send emails this is the function that i used :

 sendEmail() async {

  String username = '************@gmail.com';
  String password ='*********'; //Your Email's password;

  final smtpServer = gmail(username, password); 
  print(smtpServer);
  // Creating the Gmail server

  // Create our email message.
  final message = Message()
    ..from = Address(username)
    ..recipients.add('********@gmail.com') //recipent email
    //..ccRecipients.addAll(['destCc1@example.com', 'destCc2@example.com']) //cc Recipents emails
    //..bccRecipients.add(Address('bccAddress@example.com')) //bcc Recipents emails
    ..subject = 'Test Dart Mailer library ::  :: ${DateTime.now()}' //subject of the email
    ..text = 'This is the plain text.\nThis is line 2 of the text part.'; //body of the email

  try {
    final sendReport = await send(message, smtpServer);
    print('Message sent: ' + sendReport.toString()); //print if the email is sent
  } on MailerException catch (e) {
    print('Message not sent. \n'+ e.toString()); //print if the email is not sent
    // e.toString() will show why the email is not sending
  }
} 

but when I try to run the code it throws an exception saying: I/flutter (25924): Incorrect username / password / credentials

The username and password are correct, I tried two gmail accounts. What can be wrong?

0 Answers
Related