sidlatau / flutter_email_sender

Allows send emails from flutter using native platform functionality.
Apache License 2.0
151 stars 84 forks source link

Android 11 not handled : PlatformException(not_available,` No email clients found!, null, null) #63

Closed deacon78 closed 3 years ago

deacon78 commented 3 years ago

Hello

I got this error only on Android 11 (API 30) virtual device on Android Studio : PlatformException(not_available, No email clients found!, null, null)` The GMAIL client is already set up on the virtual device.

I do not reproduce on other devices (virtual or not) which are Android 10 or less (API 29 or less)

My code :

try {
        final Email email = Email(
          body: "some content",
          subject: "some subject",
          recipients: [''],
          attachmentPaths: [somefile.path],
          isHTML: false,
        );

        await FlutterEmailSender.send(email);
        debugPrint('email sent correctly');
      }
      catch (e) {
        debugPrint('error sending email');
        print(e);
      }
deacon78 commented 3 years ago

Could you please make flutter_email_sender compliant with Android 11 ?

deacon78 commented 3 years ago

I answer to myself : In order to make "flutter_email_sender" work with ANDROID 11 devices, here are the instructions to follow :

Step 1 In android\build.gradle file, upgrade your Android Gradle Plugin (AGP) to version 4.1 like this :

dependencies { classpath 'com.android.tools.build:gradle:4.1.1'//3.6.4'//3.6.4 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.4' }

Step 2 : In android/app/src/main/AndroidManifest.xml file, insert this section just below the tags <uses-permission> :

`

</queries>`

Step 3 : Run Flutter CLEAN

Step 4 : Run Flutter PUB GET

Step 5 : Build your APP :-)

dpedrinha commented 3 years ago

Are we the only two having this issue?

This solution works! (although it required a bunch of other updates on my end)

It should be easily implemented into the plugin.

I don't like workarounds since I know the trouble they can cause in the future. Specially when I add code just for a single plugin since I'll forget it was just a "fix".

@sidlatau any input on this? Are you working on it? Can we expect an update or should we find another plugin (just kidding mate, I'm very grateful for your plugin). I just need to know that you are alive, healthy, wealthy, still kicking and that you intend to fix it.

Cheers!

deacon78 commented 3 years ago

Hello @dpedrinha

Everyone who sets API level to 30 in the build.gradle file and then build his app and then test flutter_email_sender on an ANDROID 11 device will experience this issue.

I wonder why @sidlatau has not yet corrected this issue...

sidlatau commented 3 years ago

Readme was updated, so closing this issue.

kostadin24 commented 1 year ago

I already have implemented recommended change in AndroidMAnifest.xml - it works for Androdi 11 and 12. But not for Android 13

Works on Android13 if I not provide attachments. Also on older androids - it was able to read files from each folder in device. Now app document folder is not accessible. But plugin is not reporting issue with reaching file. It just mislead saying too general info.

bgmf commented 1 year ago

Same here. No attachments: fine. With Attachment: No email clients found! 🙄

bgmf commented 1 year ago

From what I understand, the reason behind it might be the now missing default app option, to select a default mail app. I verified this on a Pixel 6 and OnePlus 8T, both with Android 13, naturaly.

The selector process seems not te be able to find a matching app by the mailto: scheme.

With almost a day of hampering with the flutter_email_sender package localy and many Android docs and StackOverflow pages later, I've come to the following conclusion:

So far I have found only one ugly workaround (I wouldn't dare to call it a solution!). By adding

<intent-filter>
    <action android:name="android.intent.action.SENDTO" />
    <data android:scheme="my.apps.fake.scheme" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

to my AndroidManifest.xmls <activity> section and replacing my.apps.fake.scheme with our pakage ID, it works again.

I got the idea by studing the Common Intets (section Compose Email). But I needed to replace the mailto scheme with a fake one, otherwise the system thinks, your own app can handle mails...

So. It now works on my dev devices. But it is an ugly workaround, because it exposes your app as a handler for SENDTO-Events with the fake scheme...

voivoed commented 11 months ago

@sidlatau Please review this issue, it's not fixed. As described above, plugin works for Android 11 and 12, but not 13, at least in some cases. I have users on 13 that get the PlatformException(not_available, no email Managers available, null, null) error. I had to manually change the intent back to "ACTION_SENDTO" in a local copy of the plugin and have them reinstall the app from an APK so it would work again with 1 attachment.

VectorM2 commented 5 months ago

Year later and its still not fixed :)

FluffyBunniesTasteTheBest commented 3 months ago

Strange bug: If you attach a second file it works. The issue seem to happen with a single attachment only.

voivoed commented 3 months ago

Strange bug: If you attach a second file it works. The issue seem to happen with a single attachment only.

That's because it sets up the email a different way for multiple attachments. But it doesn't always work for all phones. I've even tested on 2 identical phones, same model, os version, everything. Worked on one, but not the other.

FluffyBunniesTasteTheBest commented 3 months ago

That's because it sets up the email a different way for multiple attachments.

Thanks for pointing to that!