Sending Email in Flutter Web without a Backend

132 Views Asked by At

I'm working on a Flutter web application and need to implement email sending functionality directly from the client side without using a backend server. I don't have a backend and would like to explore options within Flutter web itself.

I've looked into mailer library, but I'm unsure about the best way to achieve this without compromising security.

Specific Questions:

Is it possible to send emails directly from a Flutter web app without a backend? Are there any Flutter packages or client-side libraries that support email sending for web applications? Any guidance or code examples would be greatly appreciated. Thank you!

3

There are 3 best solutions below

0
Ghina Sharaf On BEST ANSWER

like what @randal and @faBotch said there is no way to send an email from frontend without using backend that is why i used this function:

void sendEmail(
    {required String email,
    required String subject,
    required String name,
    required String body}) async {
  String encodedSubject = Uri.encodeComponent(subject);
  String encodedBody = Uri.encodeComponent(body);
  String mailtoLink =
      'mailto:$email?subject=$encodedSubject&body=$encodedBody&headers=header1:$name';

  if (await canLaunchUrl(Uri.parse(mailtoLink))) {
    await launchUrl(Uri.parse(mailtoLink));
  } else {
    throw 'Could not launch $mailtoLink';
  }
}

and it is open the Mail application.

0
Randal Schwartz On

You will be unable to send directly from your mobile phone to any arbitrary mail server because of all the necessary spam blocking setups. You'll have to go through a trusted relay of some kind. And to use the user's mail credentials, the best you can do is open a 'mailto' URL.

So your choices are: use a mail service, or open a mailto. That's about it.

1
FaBotch On

I have not tested on web but it may works with the package url_launcher

You can try

final emailUri = Uri.parse('mailto:$EMAIL?subject=$emailSubject');
await launchUrl(emailUri);

On mobile side, it launches the default mail app but I don't know what happens on web