【问题标题】:How can I send Email from gmail to another email account如何从 gmail 发送电子邮件到另一个电子邮件帐户
【发布时间】:2020-06-25 20:39:51
【问题描述】:

我认为这是许多编码人员目前面临的问题。

所以让我们找到一个解决方案:

我已经试过了-> 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

有人知道如何在 Flutter Web 应用程序中发送电子邮件吗? (无需打开电子邮件标签)

【问题讨论】:

    标签: dart flutter-web mailer


    【解决方案1】:

    “mailer2”(和原始包“mailer”)导入dart:io,这在flutter web上是不可用的,因此你不能使用这个包。

    我过去用于发送电子邮件的一个解决方案是创建一个发送电子邮件的 http 触发云函数(例如 Firebase 函数、AWS Lambda、netlify 函数)。您可以通过 http 请求传递您需要的任何数据,并让云功能通过 Node.js 中的 nodemailer 之类的方式发送电子邮件。

    可能还有其他可用的服务或 API 已经完成了云功能的工作,虽然我没有看到很多,而且它们不是我的首选方法

    【讨论】:

      猜你喜欢
      • 2013-03-24
      • 1970-01-01
      • 2011-12-15
      • 2012-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-04-20
      • 2013-12-19
      • 1970-01-01
      相关资源
      最近更新 更多