How to compose an email with HTML in Flutter?
1,665
I found that using share one can select the standard iOS Mail app. If I pass HTML to this package, it will not launch the app separately, but will enable the user to compose the email inside the app, which is what I want:
Share.share('<html>Check out the <a href=\"https://pub.dartlang.org/packages/share\">share</a> Flutter package!</html>');
Author by
Hahnemann
Updated on December 08, 2022Comments
-
Hahnemann over 1 year
I am using flutter_email_sender to compose an email using the native iOS Mail app inside my Flutter app:
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); }
However my goal is to send HTML in the body of the email. When I pass markup to
String body
the email is composed but not in markup, just text.I am aware of url_launcher but that package launches the Mail app. I want the email composed as if I was calling MFMailComposeViewController in iOS.
-
Vinicius Pinto over 5 yearsThe current version of flutter_email_sender sets the
isHTML
parameter ofMFMailComposeViewController
tofalse
, so I guess no HTML for now. Have you triedflutter_mailer
? It allows a custom value forisHTML
, but it's a new project and the iOS support is marked as 'in progress'. -
Hahnemann over 5 yearsI have not - I'll give it a try and report back.
-
Randal Schwartz over 5 yearsJust a point of reference... I delete automatically any email that has an HTML fork but not an equivalent text fork, as 95% of that email is just spam.
-
Hahnemann over 5 yearsThe package
flutter_mailer
shows promise but I could not make it work on iOS. I'm going to stick withshare
.
-