3

I'm trying to send images using HTML in my email body but images are not sending. I don't know what I did wrong. I tried using the code below:

Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
i.setType("text/html");
String tempStr = "<html><head><title></title><style> b{ color: red}             </style></head><body><img src=\""+ "images/assaultoffences.png" + "\"><b>quick</b></body>   </html>";
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(tempStr));
i.putExtra(Intent.EXTRA_EMAIL, new String[] {"ashwini.soma@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
startActivity(i);

try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(SavePage.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
kabuko
  • 36,028
  • 10
  • 80
  • 93
user1083266
  • 1,751
  • 3
  • 24
  • 26
  • is that reference to your image src is correct ? – Jram Feb 23 '12 at 06:20
  • yes my image is correct.but in body comming small symbol only – user1083266 Feb 23 '12 at 06:28
  • You have 13 questions and most of them have multiple answers. You should really accept the best answer to each question if there is at least one that answered it to your satisfaction. – kabuko Feb 23 '12 at 07:32

4 Answers4

1

This frustratingly does not seem to be supported natively in Android. One workaround is the use Java Mail and figure it out yourself. What I did was use my droidQuery library to help write my HTML to a file and attach it to the email:

final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
String html = "<div>Place Your HTML here.</div>";
shareIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(html));
shareIntent.setType("text/html");
$.with(this).write(html, FileLocation.EXTERNAL, "email.html", false, false, new Function() {

    @Override
    public void invoke($ droidQuery, Object... params) {
        String file = ((File) params[1]).getAbsolutePath();
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file));
        startActivity(shareIntent);
    }
}, new Function() {
    @Override
        public void invoke($ droidQuery, Object... params) {
            Log.e("$", (String) params[1]);
        }
});

Then added this block at the top of the html <body> (also poorly formatted on Android email):

<div style="background: gray; color: black; align='center'" >
    Trouble viewing this email? Open the attachment to view in your web browser.
</div>

If you are considering the first approach (Java Mail), I would recommend using the droidMail extension for droidQuery, which uses the library to provide a simplified API.

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
Phil
  • 35,852
  • 23
  • 123
  • 164
0

The image needs to be hosted somewhere. When the user receives the email, the client will be looking for the image "images/assaultoffences.png" which won't exist. Host it somewhere, then specify the full URL in the email, such as http://mydomain.com/images/assaultoffences.png

IanW
  • 743
  • 5
  • 15
0

Hey you can use this reference for your solution.

I hope this will help your to solve your problem.

Thanks.

Community
  • 1
  • 1
anddev
  • 3,144
  • 12
  • 39
  • 70
0

Just because the html references an image doesn't mean the email application will read the html, parse it, find the referenced images, attach them to the email, and change the references to be internal.

There's already a question and answer describing how to attach files to emails when sending them.

This answer shows you how to reference your attached image from html to make them show up in the body (it works for Outlook at least).

Community
  • 1
  • 1
colithium
  • 10,269
  • 5
  • 42
  • 57