Android - How to find out if EMail has been sent by sending items

I have an application in which I am sending emails using intention, as shown below:

//TODO attach and send here try { Log.i(getClass().getSimpleName(), "send task - start"); String address = " emailHere@yahoo.com "; String subject = "Order of " + customer + " for " + date; String emailtext = "Please check the attached file. Attached file contains order of " + customer; final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext); ArrayList<Uri> uris = new ArrayList<Uri>(); Uri uriList = Uri.fromFile(orderListFile); uris.add(uriList); emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); this.startActivity(Intent.createChooser(emailIntent, "Send mail...")); } catch (Throwable t) { Toast.makeText(this, "Request failed: " + t.toString(), Toast.LENGTH_LONG).show(); } 

Now the user selects which application he wants to use to send this e-mail. However, as soon as the selected email application takes effect, I know that there is no way to find out if the email is sent correctly or not. Several issues are discussed here that using startActivityForIntent() does not help, since RESULT_OK never sent by EMail or GMail Ap, so I don’t know if the user sent, canceled or saved the message as a draft.

However, one possible job is to check the items sent to this email account and check from there if the user sent the email or not. Now, is there a way to find out the sent email account items in Android? I’ve been doing Google searches in the past hour, and I can’t get anything.

+6
source share
2 answers

You cannot check the contents of the ContentProvider because it requires permission, which only system applications can request. This is defined in AndroidManifest for email :

 <permission android:name="com.android.email.permission.ACCESS_PROVIDER" android:protectionLevel="signature" android:label="@string/permission_access_provider_label" android:description="@string/permission_access_provider_desc"/> … <application> … <!-- This provider MUST be protected by strict permissions, as granting access to it exposes user passwords and other confidential information. --> <provider android:name=".provider.EmailProvider" android:authorities="com.android.email.provider;com.android.email.notifier" android:exported="true" android:permission="com.android.email.permission.ACCESS_PROVIDER" android:label="@string/app_name" /> … </application> 
+6
source

For the first option, neither the standard AOSP email application nor the Gmail application behave this way. They do not return any other information if the letter was sent, saved as a draft or generally discarded.

Even if they did, the user could install another email application, and you would not have a guarantee that he would play well. And even if all email applications behave in this way, the user could edit the subject, body or "to" field, so he does not even guarantee that the "email you sent" was sent.

As for the second option , email applications usually do not export content providers. For example, the manifest for the AOSP email application shows that permission com.android.email.permission.ACCESS_PROVIDER has protectionLevel of signature , which means only applications signed by the same party (Google in this case) can access them.

Gmail used to have a content provider (via permission com.google.android.gm.permission.READ_GMAIL ), but this has been changed a long time ago (around Android 2.2, according to the comments of this answer also have protectionLevel="signature" ) and now only provides label information (see documentation ).

Given the risks of confidentiality, I would say that it is unlikely that other email clients will expose content providers to the email itself.

Depending on your actual use case, an alternative third option would be to send these emails without user interaction (such as JavaMail or a similar library). This will work, for example, if you use these emails as a way to communicate with the backend (although if so, the http message will be much more suitable).

+1
source

Source: https://habr.com/ru/post/970217/


All Articles