1

编写了用于随附件发送电子邮件的代码。一旦我发送了这封电子邮件,它就会在附件中添加一个垃圾值。附加部分以不同格式编码。

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

4 回答 4

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);
于 2012-08-09T11:05:05.310 回答
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..."));
于 2012-08-09T10:58:58.393 回答
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:"));
于 2013-04-01T13:38:04.053 回答
0

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

于 2012-08-09T10:59:52.077 回答