首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用邮件发送邮件

使用邮件发送邮件
EN

Stack Overflow用户
提问于 2020-12-09 02:04:16
回答 1查看 26关注 0票数 0

此代码在运行时返回"Message not sent“,并且不将消息发送到电子邮件。

我想用sendMail功能自动发送邮件到gmail。

我从dard pub和github复制了这段代码。

代码语言:javascript
运行
复制
sendMail() async {
      String username = '*******@gmail.com';
      String password = '*********';
      final smtpServer = gmail(username, password);
    
      final message = Message()
        ..from = Address(username)
        ..recipients.add('********@gmail.com')
        ..subject = 'Test Dart Mailer library :: ? :: ${DateTime.now()}'
        ..text = 'This is the plain text.\nThis is line 2 of the text part.'
        ..html = "<h1>Test</h1>\n<p>Hey! Here's some HTML content</p>";
    
      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}');
        }
      }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-09 09:09:05

邮件不会被发送,因为您使用的是普通的Gmail密码。只需生成应用程序密码即可。应用程序密码是一个16位数的密码,它允许非Google应用程序或设备访问您的Google帐户。

对于signing in using app passwords,请执行以下步骤。希望这篇文章能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65204382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档