使用Flutter发送邮件时的邮件程序错误

时间:2018-05-07 15:02:23

标签: email dart flutter

我实际上正在使用Flutter开发移动应用程序,我希望我可以发送一封电子邮件。为此,我尝试使用以下代码的Mailer插件:

import 'package:flutter/material.dart';
import 'package:mailer2/mailer.dart';

main() {

    var options = new GmailSmtpOptions()
      ..username = 'mer*******@gmail.com'
      ..password = '*******';

    var emailTransport = new SmtpTransport(options);

    // Create our mail/envelope.
    var envelope = new Envelope()
      ..from = 'mer*******@gmail.com'
      ..recipients.add('*******@*****.fr')
      ..subject = 'Testing the Dart Mailer library'
      ..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'));
}

但是,我有以下错误:

I/flutter (22531): Error occurred: type '_AsBroadcastStream<dynamic>' is not a subtype of type 'Stream<Envelope>' where
I/flutter (22531):   _AsBroadcastStream is from dart:async
I/flutter (22531):   Stream is from dart:async
I/flutter (22531):   Envelope is from package:mailer/mailer.dart

有人能帮助我吗?提前谢谢!

1 个答案:

答案 0 :(得分:3)

在此档案中

  

邮包-1.1.4 / LIB / SRC / SMTP /的 smtp_client.dart

更新第49行&amp; 50 by add&#34; cast()&#34;方法是:

onIdle = _onIdleController.stream.asBroadcastStream().cast(); onSend = _onSendController.stream.asBroadcastStream().cast();