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>');
Share:
1,665
Hahnemann
Author by

Hahnemann

Updated on December 08, 2022

Comments

  • Hahnemann
    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
      Vinicius Pinto over 5 years
      The current version of flutter_email_sender sets the isHTML parameter of MFMailComposeViewController to false, so I guess no HTML for now. Have you tried flutter_mailer? It allows a custom value for isHTML, but it's a new project and the iOS support is marked as 'in progress'.
    • Hahnemann
      Hahnemann over 5 years
      I have not - I'll give it a try and report back.
    • Randal Schwartz
      Randal Schwartz over 5 years
      Just 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
      Hahnemann over 5 years
      The package flutter_mailer shows promise but I could not make it work on iOS. I'm going to stick with share.