0

how to send E-mail html content with images in mail body using android

My code :

 final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
 emailIntent.setType("text/html");
 emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"to");
 emailIntent.putExtra(android.content.Intent.EXTRA_CC,"cc");
 emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"subject");
 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(body));

this.startActivity(Intent.createChooser(emailIntent, "Choose your email program"));

But mail body not display some html contains and images.

Please Help me.

Advance Thanks.

1 Answers1

1

Try with this :

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(new StringBuilder()
           .append(body).toString()));

Instead of :

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(body));

EDIT :

Here is my test and it is working well.

       String body = "<html><body><h1>this is h1</h1><b>wel come to html formet</b></body></html>";

       final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
       shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
       shareIntent.putExtra(
       Intent.EXTRA_TEXT,
       Html.fromHtml(new StringBuilder()
           .append(body).toString())
       );
       startActivity(shareIntent);

Thanks.

Pratik Sharma
  • 13,307
  • 5
  • 27
  • 37
  • i try to simple html contence display like

    this is h1

    wel come to html formet but get my json data it not display.
    – kailash barochiya Dec 31 '12 at 13:02
  • thanks pratik i try this code complite work but me add image that not display . – kailash barochiya Jan 01 '13 at 10:17
  • String body = "

    this is h1

    "; final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:")); shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject"); shareIntent.putExtra( Intent.EXTRA_TEXT,Html.fromHtml(new StringBuilder().append(body).toString())); startActivity(shareIntent);
    – kailash barochiya Jan 01 '13 at 11:03
  • @kailash refer this thread. [ http://stackoverflow.com/a/6476890/556975 ] .It is open issue with Android to send image with email body. – Pratik Sharma Jan 01 '13 at 12:12
  • thanks pratik send image in using inten not posible but other way then give me example.....thanks – kailash barochiya Jan 01 '13 at 12:39
  • @kailash yes sure. I will look into this further. Till then if my effort is helpful to you somehow then you can accept my given solution. Thanks. – Pratik Sharma Jan 01 '13 at 12:45