1

i want to put the image in my email body i have done this

Code :

protected void sendEmail() {
      Log.i("Send email", "");

      String[] TO = {"tets@gmail.com"};

      Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
      emailIntent.setData(Uri.parse("mailto:"));
      emailIntent.setType("text/plain");


      emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
      emailIntent.putExtra(Intent.EXTRA_CC, CC);
      emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
      emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
      Spanned spanned_str_Caution = Html.fromHtml(str_Caution);
      String text=tv_viewinfo.getText()+""+spanned_str_Caution;
      emailIntent.putExtra(Intent.EXTRA_TEXT, text);


      try {
          emailIntent.setType("image/png");


          int id = getResources().getIdentifier(listimgname.get(0),
                    "drawable", getPackageName());//my image gets like this 



          emailIntent.putExtra(Intent.EXTRA_STREAM, id);
         startActivity(Intent.createChooser(emailIntent, "Send mail..."));
         finish();
         Log.i("Finished sending email...", "");
      } catch (android.content.ActivityNotFoundException ex) {
         Toast.makeText(View_FoodInfoActivity.this, 
         "There is no email client installed.", Toast.LENGTH_SHORT).show();
      }
      catch (Exception e) {
           Toast.makeText(View_FoodInfoActivity.this, 
                     e.getMessage(), Toast.LENGTH_LONG).show();
    }

how it possible? i want image from drawable folder and want to display in email body... thanks in advance

Wooble
  • 87,717
  • 12
  • 108
  • 131
Android
  • 8,995
  • 9
  • 67
  • 108

1 Answers1

0

Try below code...You have to get image from drawable folder and store that to sd card and from sd card you can attach image in mail like below code :

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("application/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App"); 
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/Myimage.jpeg"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Mehul Ranpara
  • 4,245
  • 2
  • 26
  • 39