37

I want to add an image in email body. I don't want to attach an image to the email, but add an image in the email body.

How to do this?

I'm using this.

"<img src=\"data:image/png;base64,"+convertFileTOByteEncrypt()+"\">"

or

  "<img src=\"http://images.anandtech.com/doci/3982/HTCSurround-0134.jpg\">"

Then image is displayed like this.

image

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
  • 2
    Android program? Sending to an Android? What exactly do you want? – dtech Mar 09 '11 at 10:36
  • 1
    I think you're probably out of luck on this one, as support differs between mail clients... What about using plain old attachments and html mail? – Matthew Mar 14 '11 at 13:09
  • Did anyone resolve it? :) I'm facing with the same problem [here][1] [1]: http://stackoverflow.com/questions/20086975/how-to-send-email-with-image-icon-displayed-in-body-in-android – Steve Luck Dec 02 '13 at 04:08
  • @SteveLuck still not any solution for this .. – Niranj Patel Dec 02 '13 at 04:41

3 Answers3

32

Unfortunately, it's not possible to do this with Intents.

The reason why for example bold text is displayed in the EditText and not an Image is that StyleSplan is implementing Parcelable whereas ImageSpan does not. So when the Intent.EXTRA_TEXT is retrieved in the new Activity the ImageSpan will fail to unparcel and therefor not be part of the style appended to the EditText.

Using other methods where you don't pass the data with the Intent is unfortunately not possible here as you're not in control of the receiving Activity.

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
3

Here is a related question.

It seems that you can use:

intent.putExtra(Intent.EXTRA_STREAM, uri);

where uri is a file path URI.

Community
  • 1
  • 1
Matthew
  • 44,826
  • 10
  • 98
  • 87
  • Thanks Matthew. But it is attache image and i want add image in email body.. anyother code for add image in email body.. – Niranj Patel Mar 10 '11 at 04:10
  • From what I read, you can do this but most email clients won't show the image. I think you're better off using attachments or using an html link in your message body. – Matthew Mar 10 '11 at 04:32
  • Yes, You are right. But i must add image in email body as per client requirement. – Niranj Patel Mar 10 '11 at 04:50
  • ahh. Well I think the IMAGEDATA method or multipart-data is your best bet. – Matthew Mar 10 '11 at 05:12
-1

You have to create an email with HTML body and embedded image: http://www.campaignmonitor.com/blog/post/1761/embedding-images-in-email/

To send email in Android follow this recipe: How to send email in Android ?

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154