flutter 如何从Dart通过Gmail发送电子邮件?

mzillmmw  于 2023-06-30  发布在  Flutter
关注(0)|答案(1)|浏览(395)

我正在使用Dart语言和这个库:https://pub.dev/packages/mailer发送邮件通过,但我只收到此消息:

"Authentication Failed (code: 535), response:
< 5.7.8 Username and Password not accepted. Learn more at
< 5.7.8  https://support.google.com/mail/?p=BadCredentials b16-20020a9d7550000000b006b45be2fdc2sm3438416otl.65 - gsmtp"
String username = "email@gmail.com";
  String password = "password";
  final smtpServer = gmail(username, password);

  // Configurações do remetente e destinatário
  final message = Message()
    ..from = Address(
      'profept.recuperacao@gmail.com',
      'ProfEPT recuperação de senhas',
    )
    ..recipients.add(destinatario)
    ..subject = "email subject"
    ..html = "email body";

  try {
    final sendReport = await send(message, smtpServer);
    print('email send ${sendReport.mail}');
  } catch (e) {
    print('Error: $e');
  }

我尽我所能。

0s7z1bwu

0s7z1bwu1#

无法使用Gmail密码连接到Google SMTP服务器
您需要使用Oauth2或启用2fa并创建应用程序密码

相关问题