我认为这是许多编码人员目前面临的问题。
所以让我们找到一个解决方案:
我已经尝试过-> mailer2:^ 1.2.5
var options = GmailSmtpOptions()
..username = ''
..password = '';
var emailTransport = SmtpTransport(options);
var envelope = Envelope()
..from = ''
..recipients.add(email)
..subject = ''
..html = "<h1>Title </h1>\n\n"
emailTransport.send(envelope)
.then((envelope) => print('Email sent!'))
.catchError((e) => print('Error occurred: $e'));
但出现以下错误消息:
Unsupported operation: Platform._localHostname
at Object.throw_ [as throw] (http://localhost:63913/dart_sdk.js:4463:11)
at Function._localHostname (http://localhost:63913/dart_sdk.js:54754:17)
at Function.get localHostname [as localHostname] (http://localhost:63913/dart_sdk.js:54810:33)
at get _localHostname (http://localhost:63913/dart_sdk.js:54713:27)
at Function.desc.get [as _localHostname] (http://localhost:63913/dart_sdk.js:4944:15)
at Function.get localHostname [as localHostname] (http://localhost:63913/dart_sdk.js:54666:26)
at mailer.GmailSmtpOptions.new.mailer.SmtpOptions.new
(http://localhost:63913/packages/mailer2/mailer.dart.lib.js:1178:30)
at new mailer.GmailSmtpOptions.new (http://localhost:63913/packages/mailer2/mailer.dart.lib.js:1229:43)
at http://localhost:63913/packages/bestbite_native/web/screens/screen_after_order.dart.lib.js:12394:37
at Generator.next (<anonymous>)
at runBody (http://localhost:63913/dart_sdk.js:37195:34)
at Object._async [as async] (http://localhost:63913/dart_sdk.js:37226:7)
at http://localhost:63913/packages/bestbite_native/web/screens/screen_after_order.dart.lib.js:12392:389
at _RootZone.runUnary (http://localhost:63913/dart_sdk.js:37029:58)
at _FutureListener.then.handleValue (http://localhost:63913/dart_sdk.js:32116:29)
at handleValueCallback (http://localhost:63913/dart_sdk.js:32663:49)
at Function._propagateToListeners (http://localhost:63913/dart_sdk.js:32701:17)
at _Future.new.[_completeWithValue] (http://localhost:63913/dart_sdk.js:32544:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:63913/dart_sdk.js:32566:35)
at Object._microtaskLoop (http://localhost:63913/dart_sdk.js:37290:13)
at _startMicrotaskLoop (http://localhost:63913/dart_sdk.js:37296:13)
at http://localhost:63913/dart_sdk.js:32918:9Error: Unsupported operation: Platform._localHostname
有人知道如何在颤动的Web应用程序中发送电子邮件吗? (无需打开电子邮件标签)
答案 0 :(得分:0)
“ mailer2”(和原始软件包“ mailer”)将导入dart:io
,而在Flutter网站上则不可用,因此您不能使用此软件包。
我过去使用的一种发送电子邮件的解决方案是创建一个HTTP触发的云函数(例如Firebase函数,AWS Lambda,netlify函数)来发送电子邮件。您可以通过http请求传递所需的任何数据,并让云功能通过Node.js中的nodemailer
之类的方式发送电子邮件。
也许还有其他服务或API已经可以执行云功能了,尽管我没有看到很多,但它们也不是我的首选方法