【问题标题】:Flutter email sender颤振电子邮件发件人
【发布时间】:2023-03-28 18:34:01
【问题描述】:

当我从表单中发送电子邮件时出现此错误。

Unhandled Exception: PlatformException(UNAVAILABLE, defualt mail app not available, null)
class _MyAppState extends State<MyApp> {
  List<String> attachment = <String>[];
  TextEditingController _subjectController =
      TextEditingController(text: 'ct');
  TextEditingController _bodyController = TextEditingController(
      text: '''  a
  ''');
  final GlobalKey<ScaffoldState> _scafoldKey = GlobalKey<ScaffoldState>();
  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> send() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    final MailOptions mailOptions = MailOptions(
      body: 'Ro',
      subject: 'the Email Subject',
      recipients: ['rodrigo@houlak.com'],
      isHTML: true,

      attachments: [ 'path/to/image.png', ],
    );

    await FlutterMailer.send(mailOptions);

    String platformResponse;

    try {
      await FlutterMailer.send(mailOptions);
      platformResponse = 'success';
    } catch (error) {
      platformResponse = error.toString();
    }

    if (!mounted) return;
    _scafoldKey.currentState.showSnackBar(SnackBar(
      content: Text(platformResponse),
    ));
  }

【问题讨论】:

  • 如果你在模拟器上尝试,它无论如何都不会工作

标签: email flutter


【解决方案1】:

我在 iPhone 上遇到了同样的问题,这是因为我没有设置默认的 iOS 默认邮件应用程序。

【讨论】:

    【解决方案2】:

    在AndroidManifest.xml中为我添加这个可以解决这个问题:

    <application .... />
    // add queries tag for mailto intent out side of application tag
    <queries>
      <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="mailto" />
      </intent>
    </queries>
    

    【讨论】:

      【解决方案3】:
      1. 确保 Android Gradle 插件高于 4.1.0,您会在 android\build.gradle 文件中找到类似这样的内容

        依赖项 { 类路径 'com.android.tools.build:gradle:4.1.1' "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 类路径 'com.google.gms:google-services:4.3 .4' }

      2 。将其添加到您的 android/app/src/main/AndroidManifest.xml 文件中,就在您添加 &lt;uses-permission&gt; 的位置之后

      <queries> <intent> <action android:name="android.intent.action.SENDTO" /> <data android:scheme="mailto" /> </intent> </queries>
      
      1. 运行flutter clean
      2. 运行flutter pub get 或者你可以运行你的代码,它会在 Flutter 电子邮件发件人包应该适合你之后为你做这件事 这为我解决了问题

      【讨论】:

        猜你喜欢
        • 2019-12-31
        • 2019-03-04
        • 2020-10-24
        • 2021-01-08
        • 2019-01-07
        • 1970-01-01
        • 2022-07-28
        • 1970-01-01
        • 2016-03-10
        相关资源
        最近更新 更多