Flutter email sender

1,883

Solution 1

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

Solution 2

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>
Share:
1,883
R. Martinez
Author by

R. Martinez

Updated on November 26, 2022

Comments

  • R. Martinez
    R. Martinez over 1 year

    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),
        ));
      }
    
    • Murat Aslan
      Murat Aslan almost 5 years
      if you are trying it on emulator, it wont work anyway