sidlatau / flutter_email_sender

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

Attachments are not working on Android #84

Open fatihmerickoc opened 2 years ago

fatihmerickoc commented 2 years ago

I am trying to send email with attachment. When i build the code in Ios it runs with no error and perfectly but whenever i try to run in Android i got no errors but Gmail says "File could not be attached". Please Help!!

grumblebear commented 2 years ago

If you look at the sources, you will notice that this package has its own idea, how your attachments should be organized. The following ling is the problem: FileProvider.getUriForFile(activity!!, activity!!.packageName + ".file_provider", File(it)) That is a bad idea. The code should simply assume, that the user passes a correct content uri. So I propose to rename the parameter attachmentPaths to attachmentUris and leave this alone. Further I see, all attachments will get the content type "application/octet-stream". One should be able to pass the correct mime type.

MichalOneNav commented 1 year ago

Is there workaround? There is fix in 5.2.0 but not working.

tony-soft commented 10 months ago

Same problem here!

voivoed commented 8 months ago

@grumblebear what would you change on the code you mentioned above? I'm not versed in Kotlin and I'm having a hard time getting this plugin to work on Android 13. I get the attachment error message on some devices but not on others and I can't figure out why. Unfortunately none of my devices cause the errors so debugging this on my subscribers' devices is impossible.

voivoed commented 8 months ago

@sidlatau could you please look into this? This package is not working on all Android 13 devices. Unfortunately I don't have the technical expertise to fix it myself. I've tried using both single PDF file attachment and multiple file attachments, a TXT and PDF.

The files appear attached on the email composer window, but when the user taps the send button, the PDF file fails to attach with the message "File could not be attached" and the emails end up on the Draft folder instead of being sent out. The TXT file gets attached, it's just the PDF file that is consistently missing.

I found out that if the user changes anything on the email, either changing subject or body text (even by just adding a space somewhere) or selects a different account to email from the dropdown, the email goes through fine with all attachments. The problem only happens if the send button is tapped on the composer screen without anything having been changed in the email the plugin put together.

Unfortunately I can't reproduce the issue in any of my own devices, I'm working with some users that are having this problem. I tested this with my sister and her boyfriend, both have 2 identical phones with the same Android 13 version installed, configured pretty much the same, but the email attachments work in one phone but not the other.

bsutton commented 1 week ago

Has there been any forward movement on this issue. I'm see the problem on a pixel 5 with android 14 and gmail.