如何在 Flutter 中使用 HTML 撰写电子邮件?
How to compose an email with HTML in Flutter?
我正在 flutter_email_sender 使用我的 Flutter 应用程序中的原生 iOS 邮件应用程序撰写电子邮件:
import 'package:flutter_email_sender/flutter_email_sender.dart';
Future<void> sendEmail(String subject, String body) async {
final Email email = Email(
body: body,
subject: subject,
);
String platformResponse;
try {
await FlutterEmailSender.send(email);
platformResponse = 'success';
} catch (error) {
platformResponse = error.toString();
}
if (!mounted) return;
print(platformResponse);
}
但是我的目标是在电子邮件正文中发送 HTML。当我将标记传递给 String body
时,电子邮件已组成但不是标记,只是文本。
我在 iOS 中知道 url_launcher but that package launches the Mail app. I want the email composed as if I was calling MFMailComposeViewController。
我发现使用 share 可以 select 标准 iOS 邮件应用程序。如果我将 HTML 传递给这个包,它不会单独启动应用程序,但将使用户能够在应用程序内撰写电子邮件,这就是我想要的:
Share.share('<html>Check out the <a href=\"https://pub.dartlang.org/packages/share\">share</a> Flutter package!</html>');
我正在 flutter_email_sender 使用我的 Flutter 应用程序中的原生 iOS 邮件应用程序撰写电子邮件:
import 'package:flutter_email_sender/flutter_email_sender.dart';
Future<void> sendEmail(String subject, String body) async {
final Email email = Email(
body: body,
subject: subject,
);
String platformResponse;
try {
await FlutterEmailSender.send(email);
platformResponse = 'success';
} catch (error) {
platformResponse = error.toString();
}
if (!mounted) return;
print(platformResponse);
}
但是我的目标是在电子邮件正文中发送 HTML。当我将标记传递给 String body
时,电子邮件已组成但不是标记,只是文本。
我在 iOS 中知道 url_launcher but that package launches the Mail app. I want the email composed as if I was calling MFMailComposeViewController。
我发现使用 share 可以 select 标准 iOS 邮件应用程序。如果我将 HTML 传递给这个包,它不会单独启动应用程序,但将使用户能够在应用程序内撰写电子邮件,这就是我想要的:
Share.share('<html>Check out the <a href=\"https://pub.dartlang.org/packages/share\">share</a> Flutter package!</html>');