Ad

Flutter: Sending Mail To An Already Set Up Mail Address

- 1 answer

I'm trying to implement a functionality to a button inside my flutter project where the user can press on the button and automatically a prefabricated mail draft appears. Just like I'm showing it in the attached image. Is there an easy way to do this for both iOS and Android? The recipient address shall already be put inside the draft and also the subject and a part of the content, like it is shown in the image. I couldn't figure it out. Thank you very much! enter image description here

Ad

Answer

Ok I got the answer. You just simply have to use the lauchurl package and type this in:

 Future launchEmail({
    String toEmail,
    String subject,
    String message,
  }) async {
    final url =
        'mailto:$toEmail?subject=${Uri.encodeFull(subject)}&body=${Uri.encodeFull(message)}';
    if (await canLaunch(url)) {
      await launch(url);
    }
  }

Before you have to define toEmail, subject & message.

Ad
source: stackoverflow.com
Ad