【发布时间】:2021-10-01 19:32:24
【问题描述】:
您好,我想从 Flutter Web 向注册的邮箱发送邮件。我希望将随机安全码发送给新注册用户,以便他们首次登录。收件人电子邮件取自 TextFormField。我已经提到了邮件程序 pub.dev 和示例代码。下面是我添加的代码和我得到的结果。我没有为此实现做任何其他配置。
final smtpServer = gmail('email address', 'password');
final message = Message()
..from = Address('email address', 'Your Name')
..recipients.add(_emailText.text)
..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}');
}
}
var connection = PersistentConnection(smtpServer);
// Send the first message
await connection.send(message);
// close the connection
await connection.close();
这是我得到的错误:
Error: Unsupported operation: Socket constructor
at Object.throw_ [as throw] (http://localhost: )
at Function._connect (http://localhost: )
at Function.connect (http://localhost: )
at connection.Connection.new.connect (http://localhost: )
at connect.next (<anonymous>)
at runBody (http://localhost: )
at Object._async [as async] (http://localhost: )
at connection.Connection.new.connect (http://localhost: )
at connect (http://localhost: )
at connect.next (<anonymous>)
at runBody (http://localhost: )
at Object._async [as async] (http://localhost: )
at Object.connect (http://localhost: )
at send (http://localhost: )
at send.next (<anonymous>)
at runBody (http://localhost: )
at Object._async [as async] (http://localhost: )
at Object.send (http://localhost: )
at signUpForm._SignUpFormState.new.<anonymous> (http://localhost: )
at Generator.next (<anonymous>)
at http://localhost:
at _RootZone.runUnary (http://localhost: )
at _FutureListener.thenAwait.handleValue (http://localhost: )
at handleValueCallback (http://localhost: )
at Function._propagateToListeners (http://localhost: )
at _Future.new.[_completeWithValue] (http://localhost: )
at async._AsyncCallbackEntry.new.callback (http://localhost: )
at Object._microtaskLoop (http://localhost: )
at _startMicrotaskLoop (http://localhost: )
at http://localhost:
我找不到任何相关的解决方案。我错过了什么还是有更简单的方法来实现这个?希望有人可以提供帮助。非常感谢!
【问题讨论】:
标签: firebase email flutter-web