You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

flutter_email_sender发送邮件失败,更换mailer包解决问题

解决flutter_email_sender的PlatformException(not_available)问题

将flutter_email_sender的README代码复制到示例项目后,发送邮件时始终抛出错误:PlatformException(not_available, No email clients found!, null, null)。即便已经按照要求添加了Android 11所需的权限,问题仍未解决。

最终改用mailer包解决问题,该包使用更简便、文档更丰富,支持自定义SMTP配置。

发送邮件示例代码

sendMail() async {
  final email = 'email';
    
  final smtpServer = smtpserver('aa@aa.com', 'pwd');
    
  final msg = Message()
    ..from = Address(email)
    ..recipients = ['aaa@aaa.com']
    ..subject = 'this works!'
    ..text = 'something';
    
  String platformResponse;
    
  try {
    await send(msg, smtpServer);
    platformResponse = 'success';
    print(platformResponse);
  } catch (error) {
    print(error);
    platformResponse = error.toString();
  }
}

SMTP配置示例

import 'package:mailer/smtp_server.dart';

SmtpServer config_smtp(String username, String password) =>
    SmtpServer('your.smtp.com', username: username, password: password);

内容的提问来源于stack exchange,提问作者Gegob

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 06:54:34