代码之家  ›  专栏  ›  技术社区  ›  CoXier

在DART中发送QQ邮件

  •  0
  • CoXier  · 技术社区  · 6 年前

    我正在使用 mailer 用于发送主机为的邮件的包 QQ 这在中国很流行。

    String username = 'xx@qq.com';
    String password = 'xx';
    
    final smtpServer = new SmtpServer("smtp.qq.com", port: 465, username: username, password: password);
    
    // Create our message.
    final message = new Message()
      ..from = new Address(username, 'Your name')
      ..recipients.add('receiver@qq.com')
      ..subject = 'Test Dart Mailer library :: 😀 :: ${new 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>";
    
    final sendReports = await send(message, smtpServer);
    

    但是失败了。我还剩下什么吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   close2    6 年前

    QQ SMTP服务器需要SSL标志:

    String username = 'xx@qq.com';
    String password = 'xx';
    
    final smtpServer = new SmtpServer("smtp.qq.com", ssl: true, port: 465, username: username, password: password);
    

    (注意 ssl: true 争论)。

    此外,2.2.0版现在有一个 qq(username, password) SMTP服务器定义函数(类似于 gmail 函数)。