I am trying to send an email via ACTION_SEND from my database in my app. All is working and all fields with user details are formatted correctly in the email body using html. However when i need to send an Image as well (using standard built in email client on android) i get a toast showing "Unable to attach file"
I have search and tried various solutions from SO but none of them helped me.
So this is what i have:
Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = {"user@example.com", "user1@example.com"};
messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
messageIntent.putExtra(Intent.EXTRA_CC, new String[]{"user2@example.com", "user3@example.com"});
messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
messageIntent.setType("text/html");
messageIntent.setType("image/png");
messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
Log.v(getClass().getSimpleName(), "simageUri=" + Uri.parse("file://"+ image));
messageIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ image));
startActivity(messageIntent);
}
Now image is where the file is saved in my database. I have tried image.getAbsolutePath
but this crashes with a null pointer exception
In my String.xml I have to body of the email.
<string
name="feedbackmessagebody_format">
<![CDATA[
<html>
<head>
<style>
table {
border-collapse: collapse;
}
td, th {
border: 1px solid black;
padding: 3px;
}
</style>
</head>
<body>
<table>
<col width="300">
<tr>
<th>Field</th>
<th>Description</th>
</tr>
<tr>
<td><b>Image: </b></td>
<td>%22$s</td>
</tr>
</table>
</body>
</html>
]]></string>
The %22$s is the number of fields i have in my email body and this is pointing to
final ImageView feedbackField19 = (ImageView) findViewById(R.id.imageA);
String feedback22 = feedbackField19.getDrawable().toString();
Not sure what i am missing here?