例外:不支持的操作:Platform._localHostname

时间:2019-03-05 16:35:01

标签: dart smtp sendmail mailer

我是Angledart的新手,正在从事邮寄工作,但出现错误消息:

  

dart_sdk.js:100398   例外:不支持的操作:   Platform._localHostname STACKTRACE:dart:sdk_internal
  获取本地主机名包:mailer2 / src / smtp / smtp_options.dart 4:25
  新包装:mailer2 / src / smtp / helper_options.dart 12:24
  新   软件包:DigitalHrSummit / src / components / homepagecomponent / homepage_component.dart   68:21提交   软件包:DigitalHrSummit / src / components / homepagecomponent / homepage_component.template.dart   1025:8 [_handle_click_287_0]   封装:angular / src / core / linker / app_view.dart 602:29
  src__core__linker__app_view_utils.appViewUtils.eventManager.zone.runGuarded.dart.fn   封装:angular / src / core / zone / ng_zone.dart 134:16
  parent.run.dart.fn dart:sdk_internal
  运行package:angular / src / core / zone / ng_zone.dart 131:18
  [_run] dart:sdk_internal
  runGuarded软件包:angular / src / core / zone / ng_zone.dart 302:22
  runGuarded软件包:angular / src / core / linker / app_view.dart 601:37
  事件

基本上,我只是可以找到here的示例代码。我在选项变量中有我的Gmail用户名和密码。

我的.dart组件(homepage_component.dart)中有示例代码

...
import 'package:mailer2/mailer.dart';
...
class HomeComponent(){
void onSubmit(Map<String, dynamic> contactUsInfo) {


    //Gmail account used to send email
      var options = new GmailSmtpOptions()
    ..username = 'my-gmail-account'
    ..password = 'my-gmail-password';




    // Create our email transport.
    var emailTransport = new SmtpTransport(options);

  // Create our mail/envelope.
  var envelope = new Envelope()
    ..from = 'sender-email-here'
    ..recipients.add('recievers-mail-here')
    //..bccRecipients.add('hidden@recipient.com')
    ..subject = 'Testing the Dart Mailer library'
    //..attachments.add(new Attachment(file: new File('path/to/file')))
    ..text = 'This is a cool email message. Whats up?'
    ..html = '<h1>Test</h1><p>Hey!</p>';

// Email it.
  emailTransport.send(envelope)
    .then((envelope) => print('Email sent!'))
    .catchError((e) => print('Error occurred: $e'));



  }
}

请帮助我。谢谢。

1 个答案:

答案 0 :(得分:0)

该库get_context_data,因此无法在网络上使用。