1

I am using the following code to send html format to send email in Android; now I want to send Image with it.

   private void friends_email_share() {

    Log.i("Send email", "");
    String mail_body = "<!DOCTYPE html><html><body>\n" +
            "    <p>Hi,</p>\n" +
            "    <p>Lorem Ipsum <b>Lorem Ipsum Lorem Ipsum Lorem IpsumLorem </b> Lorem IpsumLorem  Ipsum</p>\n" +
            "    <p>Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum.</p>\n" +
            "    <p>Lorem IpsumLorem  IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum.</p>\n" +
            "    <p>Lorem IpsumLorem  IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum.</p>\n" +
            "    <p>Lorem IpsumLorem IpsumLorem IpsumLorem  IpsumLorem IpsumLorem Ipsum.</p>\n" +
            "</body></html>";
    String[] TO = {};
    String[] CC = {};
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.setType("text/html");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
    emailIntent.putExtra(Intent.EXTRA_CC, CC);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Extra Subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "" + "\n" + Html.fromHtml(mail_body));
    try {
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        //getActivity().finish();
        Log.i("-->", "Finished sending email...");
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(getApplicationContext(), "There is no email client installed.", Toast.LENGTH_SHORT).show();
    }

What are the possible ways to send Image via email in android?

I need a serious help here, thank you ....

Dev
  • 13,492
  • 19
  • 81
  • 174
Santosh Bhandary
  • 359
  • 2
  • 3
  • 19
  • http://stackoverflow.com/questions/7604498/android-how-to-send-an-image-as-email-attachment-from-application – GOLDEE May 25 '15 at 09:27

2 Answers2

1

This might help you..

try{

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);  
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "android@abcxyz.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Emergency");         
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+ path + "/" + image_name));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Please Find Attachments");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
} catch (Throwable t) {
    Toast.makeText(MainActivity.this, "Request failed: " + t.toString(),Toast.LENGTH_LONG).show();
}

}

  • As you guys said I used Intent.ExtraStream ,but the problem is it doesnot throw any errors but ,I am trying to load load local image stored in json and Used the code " String image_path = "all_images/" + species_image + ".jpg"; image_name_array.add(image_path); emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(image_path));" – Santosh Bhandary May 25 '15 at 11:35
  • what am I missing guys @bigO any Suggestion on this ?, – Santosh Bhandary May 25 '15 at 11:37
  • @SantoshBhandary i edited my answer above, your image_path should be wrong. You need to get the image from assets folder if it is in the assets folder. – yrazlik May 26 '15 at 07:16
0

You can find the answer here.

About your question, you can add the image in the assets folder as an attachment like this:

 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("application/image");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "Text text");
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"This is email subject");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is extra text");
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///android_asset/allimages/demoImage.jpg"));
    startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Hope this helps.

Community
  • 1
  • 1
yrazlik
  • 10,411
  • 33
  • 99
  • 165
  • What should I have to do.I want to send image from assets folder .I am Saving Image is assets Folder as :-"assets/allimages/demoImage.jpg" – Santosh Bhandary May 26 '15 at 06:43