sendEmail static method

Future<void> sendEmail({
  1. required String toEmail,
  2. required String subject,
  3. required String body,
})

A function to send an email.

It takes a String for toEmail, subject, and body.

It will try to launch the email with LaunchMode.externalApplication.

If the launch fails, it will throw an Exception.

Implementation

static Future<void> sendEmail({
  required String toEmail,
  required String subject,
  required String body,
}) async {
  final emailLaunchUri = Uri(
    scheme: 'mailto',
    path: toEmail,
    query:
        '${Uri.encodeQueryComponent('subject')}$subject&${Uri.encodeQueryComponent('body')}=$body',
  );
  if (!await launchUrl(emailLaunchUri)) {
    throw Exception('Could not launch $emailLaunchUri');
  }
}