附加图像没有收到邮件

时间:2013-02-11 10:45:37

标签: android

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
        emailIntent.setType("image/jpg");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] 
        {"me@gmail.com"}); 
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
        "Test Subject"); 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
        "go on read the emails"); 
        Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:///sdcard/2944154479.jpg"));
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/2944154479.jpg"));
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));

我使用上面的代码将图像发送到电子邮件,电子邮件页面显示该文件已附加 但我只得到消息,附件没有收到我的邮件。

请帮忙 提前致谢

3 个答案:

答案 0 :(得分:0)

请尝试以下适用于您的代码。

  Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
          emailIntent.setType("jpeg/image");
          emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                       new String[] { "" });
          emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
          Date cal = Calendar.getInstance().getTime();
          emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body");

          Uri uri = Uri.fromFile(new File(Environment
                       .getExternalStorageDirectory(), "/HB.jpg"));

          emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
          emailIntent.setType("text/plain");

          startActivity(Intent.createChooser(emailIntent, "Send mail..."));

答案 1 :(得分:0)

首先,您必须将类型设置为text/plain才能添加消息。然后将类型设置为jpeg/image以添加图像。否则,您的信息将被误解。

   Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getResources().getString(R.string.emlSendToFriendSubject));
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailto});
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getResources().getString(R.string.emlSendToFriendBody));
    File file = getFileStreamPath(EMAIL_TEMP_FILE);
    emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    emailIntent.setType("image/jpeg");
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath()));
    startActivityForResult(Intent.createChooser(emailIntent, getResources().getString(R.string.btnSendToFriend)),ActMain.EMAIL_DONE);

答案 2 :(得分:0)

试试这个:)

String path = ...;

//Need to remove file:////, it has to be something like this storage/emulated/0/repertory/image.jpg
 if(path.startsWith("file")){
    path = path .replace("file:////", "");
 }

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"test@test.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT   , "body");
startActivity(Intent.createChooser(i, "Sending email..."));