错误后发送的邮件:邮件包颤抖

时间:2020-07-20 14:42:37

标签: flutter dart smtp mailer

我正在尝试使用Flutter中的mailer软件包发送带有附件的电子邮件,但是我的邮件在发生错误后发送。该错误是什么,我该如何解决?

我已在我的gmail帐户中打开了用于发送电子邮件的不太安全的访问权限。

这是我的代码:

  final smtpServer = gmail('username', 'pass');
    // Creating the Gmail server

    final file = File(_filepath);

    // Create our email message.
    final message = Message()
      ..from = Address('username')
      ..recipients.add(_recipientController.text.trim()) //recipent email
      ..subject = _subjectController.text //subject of the email
      ..text = _bodyController.text
      ..attachments.add(FileAttachment(file)); //body of the email

    try {
      final sendReport = await send(message, smtpServer);
      print('Message sent: ' + sendReport.toString());

      _scaffoldKey.currentState.showSnackBar(SnackBar(
        content: Text('Email Sent !'),
      )); //print if the email is sent
    } on SmtpMessageValidationException catch (e) {
      print('Message sending error' + e.toString());
    } on MailerException catch (e) {
      print('Message not sent. \n' + e.toString());
      for (var p in e.problems) {
        print('Problem: ${p.code}: ${p.msg}');
      }
    
    }

。 。

这是我遇到的错误:

E/flutter (11764): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Invalid message.
E/flutter (11764): #0      _validate (package:mailer/src/smtp/mail_sender.dart:118:5)
E/flutter (11764): #1      send (package:mailer/src/smtp/mail_sender.dart:92:3)
E/flutter (11764): #2      _SendEmailScreenState.sendDirectly (package:invoice_app/send_pdf_screen.dart:84:32)
E/flutter (11764): #3      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19)
E/flutter (11764): #4      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:862:36)
E/flutter (11764): #5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (11764): #6      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
E/flutter (11764): #7      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
E/flutter (11764): #8      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7)
E/flutter (11764): #9      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9)
E/flutter (11764): #10     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter (11764): #11     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter (11764): #12     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter (11764): #13     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter (11764): #14     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter (11764): #15     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (11764): #16     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (11764): #17     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (11764): #18     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (11764): #19     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (11764): #20     _rootRunUnary (dart:async/zone.dart:1196:13)
E/flutter (11764): #21     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (11764): #22     _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter (11764): #23     _invoke1 (dart:ui/hooks.dart:275:10)
E/flutter (11764): #24     _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)
E/flutter (11764): 

0 个答案:

没有答案