Home > Net >  Flutter: sending mail to an already set up mail address
Flutter: sending mail to an already set up mail address

Time:12-18

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

CodePudding user response:

There is an easy to use package for this that will save you a bunch of time from recreating the wheel. When trying to find common solutions like this that many others would benefit from, I would suggest checking out www.pub.dev first as there are a lot of very helpful packages out there like this:

https://pub.dev/packages/flutter_email_sender

CodePudding user response:

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.

  • Related