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
相关产品推荐
相关产品推荐

