sidlatau / flutter_email_sender

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

Send email with attachments not working on Android 13 #87

Closed kostadin24 closed 1 year ago

kostadin24 commented 2 years ago

This code works fine on Android versions before 13: final Email email = Email( body: _body, subject: 'Network information', recipients: ['$_supportEmail'], //cc: ['cc@example.com'], //bcc: ['bcc@example.com'], attachmentPaths: attachments,//Files are in app document folder isHTML: false, );

On Android 13 it says: PlatformException(not_available, No email clients found!, null, null) Version of plugin is: flutter_email_sender: ^5.1.0 I have mail client on my phone and it is selected as default.

It works on Android 13 it if remove attachments. Files are in app document folder. This folder was visible in previous androids. But with recent versions Android may be limit access to this folder.

explorer2050 commented 2 years ago

+1 same problem mentioned above seen on Pixel 5 "On Android 13 it throws: PlatformException(not_available, No email clients found!, null, null)". If user has only gmail installed, it will not work. Are there any plans to fix this issue?

rafaellop commented 2 years ago

Please try adding this to your manifest:

            <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
            <queries>
                <intent>
                    <action android:name="android.intent.action.SENDTO" />
                    <data android:scheme="mailto" />
                </intent>
            </queries>
kostadin24 commented 2 years ago

I have this added already. It helped me before plugin started targeting android 13. But now is not the solution.

On Sat, Nov 12, 2022, 15:05 rafal.platek @.***> wrote:

Please try adding this to your manifest:

        <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
        <queries>
            <intent>
                <action android:name="android.intent.action.SENDTO" />
                <data android:scheme="mailto" />
            </intent>
        </queries>

— Reply to this email directly, view it on GitHub https://github.com/sidlatau/flutter_email_sender/issues/87#issuecomment-1312474782, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADUOHKHXECL5JOZ7CVLKYC3WH6I2LANCNFSM6AAAAAARP4GEEU . You are receiving this because you authored the thread.Message ID: @.***>

Douglal commented 2 years ago

Hello, I am having exactly the same issue as kostadin24 I have added the statement in Android manifest and flutter_email_sender works fine with no attachement. However with an attachement it fails with this error on Android 13: PlatformException(not_available, No email clients found!, null, null) flutter_email_sender is a great package (thanks sidlatau) and has worked reliably in my live app for 2 years on Android and iOS sidlatau, please fix this as soon as possible as my Path Checker app has hundreds of users!

Douglal commented 2 years ago

The attachment in my app is a .jpg image selected from the gallery or the camera using image_picker. The picked image displays fine on screen using Image.file(File(pickedFile.path)) but flutter_email_sender now fails on Android 13 with attachments.add(pickedFile.path). This error happens on Google Pixel 4a and 6a. I hope that this extra information helps you to solve the problem quickly for us all.

sidlatau commented 2 years ago

Hmm, I am unable to reproduce the problem. Does an example app work for you? Does an error appear in an emulator? How many files you are attaching?

Douglal commented 2 years ago

Thank you for the quick reply. As you can see above several people are having this same problem. My Path Checker app is using your example code (using just one attachment) and it still works fine for iPhone and for earlier versions of Android (it worked correctly on my old Samsung Galaxy S9 but doesn't on my new Galaxy Pixel 6a). I am using Visual Studio Code on Windows 10 and the error "PlatformException(not_available, No email clients found!, null, null)" occurs in the Pixel 4a emulator (but the email is created with an attachment and no error in the Galaxy S9 emulator). The pickedFile.path is like this: /data/user/0/com.colton.path_checker/cache/image_picker12345678901234567890.jpg Do you think the way that Android 13 caches images from the gallery and from the camera is part of the problem? I have just given you access to my app's source code repository at github.com/Douglal/path_checker

kostadin24 commented 2 years ago

I'm attaching files stored in app document folder. They are binary data, not image/video/etc. so caching in gallery is not my case.

sidlatau commented 1 year ago

I was able to reproduce a problem. It should be fixed in v5.2.0. If you still have a problem, please reopen this or create a new issue.

BarreseCA commented 11 months ago

i have the same problem: PlatformException(not_available, No email clients found!, null, null) if i send e-mail with attachmentPaths in android 13.

final File? imageFile = image != null ? await _createImageTempDirectory(image, imageName) : null;

final Email email = Email(
  subject: subject,
  recipients: recipients,
  cc: cc,
  body: body,
  attachmentPaths: imageFile != null ? [imageFile.path] : null,
  isHTML: false
);

i read image from: Future _createImageTempDirectory(Uint8List image, String imageName) async { final Directory tempDir = await getTemporaryDirectory(); final String filePath = '${tempDir.path}/$imageName.jpg';

return await File(filePath).writeAsBytes(image);

}