0

I have two problems with the url_launcher: ^5.7.10 First Problem: When I try to send an email with html tag, on a real device, if I use Gmail application the body of my email is not well formated. I see the HTML tags. I tried with or without HTML5 doctype Second Problem: When I try to send an email with an Href tag the email body is cut at the equal sign.

My code is

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'URL Launcher',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'URL Launcher'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  Future<void> _sendMailHtml(String url) async {
    if (await canLaunch(url)) {
      await launch(
        url
      );
    } else {
      throw 'Could not launch $url';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: ListView(
        children: <Widget>[
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[

              RaisedButton(
                onPressed: () => setState(() {
                  _launched = _sendMailHtml('mailto:smith@example.org?subject=News&body=<h1>Header 1</h1><p>Paragraph</p>');
                }),
                child: const Text('Send Mail HTML'),
              ),
              RaisedButton(
                onPressed: () => setState(() {
                  _launched = _sendMailHtml('mailto:smith@example.org?subject=News&body=<h1>Header 1</h1><p>Paragraph</p><a href="https://google.com">Link</a><p>End of mail</p>');
                }),
                child: const Text('Send Mail HTML With HREF'),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

My pubspec.yaml is

name: flutter_app
description: A new Flutter application.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  url_launcher: ^5.7.10
  cupertino_icons: ^1.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter

# The following section is specific to Flutter.
flutter:

  uses-material-design: true

I did not try with flutter 2 because my app is in production and I have some dependencies errors.

For the first problem if I try with another email app, I can see the good formatting.

On Android 10...

screenshots :

first problem on Gmail app

on other email app

Second problem with Gmail and anchor tag

1 Answers1

0

The mailto body parameter only supports plaintext messages. See this question.

If you want you can check out the mailer package which has an interface for sending HTML emails, as shown in the linked page.

Anis R.
  • 6,656
  • 2
  • 15
  • 37
  • But Mailer send the email with a SMTP Server, I want open the email app of the phone. Edit And if you look one of my screenshot you will see that it worked on an email app. – Olivier Maily Jun 23 '21 at 13:22