3

Is it possible to programatically embed an image in the body of an email sent by the Mail app in Android?

Can I use the ACTION_SEND intent to do this, or should I compose the email myself?

2 Answers 2

6

to put the image in the body, you need to set the content type to "text/html" and then put an img tag in the email body. if you don't want to use a webserver to host the image, then you can use a data uri for the image.

Info & Sample:

<img src="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP
C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA
AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J
REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Red dot" />

If you want to attach an image to the email, you use the putExtra method and set it to EXTRA_STREAM.

emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, myImageStream);
Sign up to request clarification or add additional context in comments.

5 Comments

i have tried this, but this displays only the string, not an image, please.. can you give the exact code...
if you see text, then you are not setting the content type to "text/html"
i also got same issue @kalandar. have you got any solution ?
@RyanConrad Will You Please, Elaborate it in Detail ?
@user5716019 elaborate what in detail? This has all of the details that would be needed to embed an image in an email. What other information are you looking for?
4

If your image (or file) is in the SD card, you can proceed as follow:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/your_path_in_the_sd_card/your_image.png"));
startActivity(shareIntent);

If you don't want to send image, you need to modify the MIME in the "setType()" method.

For more details check this post.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.