Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter email sender

Tags:

email

flutter

I have this error when I send an email from form in flutter.

Unhandled Exception: PlatformException(UNAVAILABLE, defualt mail app not available, null)
class _MyAppState extends State<MyApp> {
  List<String> attachment = <String>[];
  TextEditingController _subjectController =
      TextEditingController(text: 'ct');
  TextEditingController _bodyController = TextEditingController(
      text: '''  a
  ''');
  final GlobalKey<ScaffoldState> _scafoldKey = GlobalKey<ScaffoldState>();
  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> send() async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    final MailOptions mailOptions = MailOptions(
      body: 'Ro',
      subject: 'the Email Subject',
      recipients: ['[email protected]'],
      isHTML: true,

      attachments: [ 'path/to/image.png', ],
    );

    await FlutterMailer.send(mailOptions);

    String platformResponse;

    try {
      await FlutterMailer.send(mailOptions);
      platformResponse = 'success';
    } catch (error) {
      platformResponse = error.toString();
    }

    if (!mounted) return;
    _scafoldKey.currentState.showSnackBar(SnackBar(
      content: Text(platformResponse),
    ));
  }
like image 845
R. Martinez Avatar asked May 17 '26 17:05

R. Martinez


2 Answers

Adding in AndroidManifest.xml this for me on Android solve the issue:

<application .... />
// add queries tag for mailto intent out side of application tag
<queries>
  <intent>
    <action android:name="android.intent.action.SENDTO" />
    <data android:scheme="mailto" />
  </intent>
</queries>
like image 143
Gianluca Cisana Avatar answered May 20 '26 05:05

Gianluca Cisana


I had the same issue on iPhone, it was caused because I hadn't set up the default iOS default Mail App.

like image 45
Wei Jason Avatar answered May 20 '26 05:05

Wei Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!