Home > Back-end >  flutter_email_sender doesn't send email
flutter_email_sender doesn't send email

Time:08-04

I just copied the readme file and put it into an example project, Im trying to send a email but it always have the same error.

PlatformException(not_available, No email clients found!, null, null)

There's my code:

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Mandar Correo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Manda Correo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Title'),
        centerTitle: true,
      ),
      body: Center(
        child: ElevatedButton(
          style: ElevatedButton.styleFrom(
            padding: EdgeInsets.all(20),
            textStyle: TextStyle(fontSize: 24),
          ),
          child: const Text('Enviar Correo'),
          onPressed: sendMail,
        ),
      ),
    );
  }
}

sendMail() async {
  final Email email = Email(
    body: "example",
    subject: "title",
    recipients: ['bb@bb'],
    cc: ['aa@aa'],
    isHTML: false,
  );

  String platformResponse;

  try {
    await FlutterEmailSender.send(email);
    platformResponse = 'success';
  } catch (error) {
    print(error);
    platformResponse = error.toString();
  }
}

AndroidManifest.xml, it says that Android v.11 needs some permisions. So i just copy them.

CodePudding user response:

add this in AndroidManifest.xml

<manifest package="com.mycompany.myapp">
  <queries>
   <intent>
    <action android:name="android.intent.action.SENDTO" />
    <data android:scheme="mailto" />
   </intent>
  </queries>
</manifest>

check here for more info

CodePudding user response:

May be this package can help you. I am using this package for sending emails url_launcher: ^6.1.5. It was quite succesfull every time I used it. So if it is not important what package you should use you can try it out.

Also always recommend to test such things in real device. Sometimes it could not work on emulator

  • Related