电子邮件附件图片无法发送

时间:2012-08-09 10:49:12

标签: android android-layout

编写用于沿附件发送电子邮件的代码。发送此电子邮件后,它会在附件中添加垃圾值。 附件以不同的格式编码。

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..."));

预期: 它应该是附加的图像文件而不是编码的字符串。

任何帮助都会非常感激。 提前谢谢。

4 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

您需要设置您的意图类型以正确处理图像,假设它是png,如下所示。

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..."));

答案 2 :(得分:0)

如果你在邮件上发送Jpg图像...只需写i.setType(“image / jpeg”);并发送任何文件只需写入i.setType(“image / *”);

答案 3 :(得分: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:"));