SmtpClientAuthenticationException(用户名/密码/凭据不正确)邮件扑朔迷离

请任何人都可以在我的flutter项目中帮助解决此错误。有一个主要问题是,如果我直接使用命令“ flutter run”运行我的项目。它运行完美,但是。如果运行调试,则会出现上述错误,并在下面共享一个错误。

  1. pubspec.yml
System.out.println(e);
  1. 这是主文件。
dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  mailer: ^3.0.4
  1. 发送邮件的代码
import 'package:flutter/material.dart';
import 'package:mail_example/mail.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: Text("Mail Example"),),body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,children: <Widget>[
            RaisedButton(
              onpressed: () async {
                await mail();
              },child: Text("send Mail"),)
          ],));
}
  1. 在调试过程中出错。
import 'package:mailer/mailer.dart';
import 'package:mailer/smtp_server.dart';

Future mail() async {
  String username = 'myemialaddress@gmail.com';
  String password = 'mymailpassword';

  final smtpServer = gmail(username,password);
  // Use the SmtpServer class to configure an SMTP server:
  // final smtpServer = SmtpServer('smtp.domain.com');
  // See the named arguments of SmtpServer for further configuration
  // options.

  // Create our message.
  final message = Message()
    ..from = Address(username,'name in mail address')
    ..recipients.add('secondmailid') // where i am sending test message.
    ..subject = 'Test Dart Mailer library'
    ..text = 'This is the plain text.This is line 2 of the text part.';

  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}');
    }
  }
  // DONE
  // Sending multiple messages with the same connection
  //
  // Create a smtp client that will persist the connection
  var connection = PersistentConnection(smtpServer);

  // Send the first message
  await connection.send(message);

  // close the connection
  await connection.close();
}

我知道它正在使用命令抖动运行。但我需要确定。如果我将我的应用程序部署在Google Play和Apple Store上。它工作完美。 您的答案将是可观的。

LIUYAOZU 回答:SmtpClientAuthenticationException(用户名/密码/凭据不正确)邮件扑朔迷离

转到并关闭要发送邮件的Google帐户的安全性: https://myaccount.google.com/lesssecureapps

本文链接:https://www.f2er.com/2562464.html

大家都在问