PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 18, 2022

[FIXED] How to compose an email with HTML in Flutter?

 July 18, 2022     dart, document-body, email, flutter, html     No comments   

Issue

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.


Solution

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>');


Answered By - Hahnemann
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing