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

Flutter使用url_launcher发送HTML格式邮件的实现问题

实现带HTML可点击链接的邮件正文

首先要明确:mailto URI协议本身不支持解析HTML格式的正文,你传入的<a>标签会被系统邮件客户端当作纯文本直接显示,所以设置IsHtml类参数完全无效——这些参数对mailto协议不生效。

要实现“here”作为可点击链接文本的需求,你需要改用支持HTML邮件的第三方库,比如flutter_email_sender,具体步骤:

  1. 在pubspec.yaml中添加依赖:
dependencies:
  flutter_email_sender: ^5.2.0
  1. 使用以下代码发送带HTML正文的邮件:
import 'package:flutter_email_sender/flutter_email_sender.dart';

final Email email = Email(
  subject: 'Invitation',
  body: 'Hi, Click <a href="https://google.com">here</a> to launch Google',
  isHTML: true, // 开启后邮件客户端会解析HTML内容
);

await FlutterEmailSender.send(email);

如果非要用url_launcher,只能退而求其次,让客户端自动识别纯文本URL:

final Uri url = Uri(
  scheme: 'mailto',
  path: '',
  query: 'subject=Invitation&Body=Hi, Click here to launch Google: https://google.com',
);
launchUrl(url);

这种方式下,系统会把https://google.com识别为可点击链接,但无法将“here”设为链接文本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 10:35:27