1

Written a code for send an email along attachment. Once I sent this email it added a garbage value in attachment. Attached part was encoded in different format.

Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {"user_one@example.com", "user_two@example.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + sPhotoFileName));
i.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(mailBody));
startActivity(Intent.createChooser(i, "Send mail..."));

Expected: It should a attached images files other than encoded string.

Any help would highly appreciate . Thanks in advance.

QuokMoon
  • 4,387
  • 4
  • 26
  • 50
  • go through the following [post](http://stackoverflow.com/questions/11465796/will-anyone-give-example-for-sending-mail-with-attachment-in-android/11467525#11467525) it solves your problem. – Harish Sep 14 '12 at 06:54

4 Answers4

1
File jpegfile = new File(imageDir, "yourfilename.jpeg");

Uri jpegurl = Uri.fromFile(jpegfile);

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/jpeg"); //
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "mailid@domain.com" });
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail Subject");
intent.putExtra(android.content.Intent.EXTRA_CC, new String[] { "mailid@domain.com" });
intent.putExtra(Intent.EXTRA_TEXT, "Mail body text");
intent.putExtra(Intent.EXTRA_STREAM, jpegurl);
Bucks
  • 689
  • 3
  • 11
  • 28
0

You need to set your intent type to handle images properly, assuming it is a png, as follows.

Intent emailIntent = new Intent(Intent.ACTION_SEND, Uri.fromFile(temp));
emailIntent.setType("image/png");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_share_subject));
emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_share_message));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(temp));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
luuts
  • 652
  • 4
  • 12
0

if u Send Jpg image on sen mail...just write i.setType("image/jpeg"); and send any file just write i.setType("image/*");

ckpatel
  • 1,926
  • 4
  • 18
  • 34
0
i've done for send any file from SD card with mail attachment..

Intent sendEmail= new Intent(Intent.ACTION_SEND);
       sendEmail.setType("rar/image");
       sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new        
         File("/mnt/sdcard/download/abc.rar")));
         startActivity(Intent.createChooser(sendEmail, "Email:"));
pradip
  • 185
  • 1
  • 3
  • 11