Android: Sending E-mail with attachment through Share Intent

Sree Kumar A.V
1 min readMar 1, 2019

Share intent is pretty easy to share contents with other apps. But it works pretty well if you sent the proper MIME type. Things get messy if you want to share an attachment with e-mail client installed in the device.

Unfortunately, the ACTION_SENDTO Intent doesn’t support attachments. You have to choose Intent.ACTION_SEND.

/**
* E-mail intent for sending attachment
*/
private fun sendEmail() {
LogUtils.d(TAG, "Sending Log ...###### ")
val emailIntent: Intent = Intent(Intent.ACTION_SEND)
emailIntent.type = "message/rfc822"
emailIntent.putExtra(Intent.EXTRA_SUBJECT, SUBJECT_EMAIL)
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(SUPPORT_EMAIL))
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
emailIntent.putExtra(Intent.EXTRA_TEXT, BODY_EMAIL)
try {
context?.startActivity(Intent.createChooser(emailIntent, INTENT_CHOOSER_MESSAGE))
} catch (ex: ActivityNotFoundException) {
LogUtils.d(TAG, "No Intent matcher found")
}

}

--

--