如何发送带附件的电子邮件(图片)

时间:2012-03-25 12:38:31

标签: android image sendmail

我尝试了两种方式send email带图像附件。附件显示在撰写主题时,boby一切都在接收器后面的电子邮件中它只显示subject & Body只有用户没有受到影响得到。我不明白我的代码下面的代码是我的代码。请给我任何建议来完成这项任务。

类型1: -

   Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
   picMessageIntent.setType("image/jpeg");
   File downloadedPic = new File(Environment.getExternalStorageDirectory(), strFileName + ".jpg");// Art_Nature
   picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));//screenshotUri );//Uri.fromFile(new File("downloadedPic"))); //Uri.fromFile(downloadedPic)); // Uri.fromFile(new File("/path/to/downloadedPic")));
        startActivity(Intent.createChooser(picMessageIntent, "Share image using"));

类型2:

 ArrayList<Uri> uris = new ArrayList<Uri>();   
 Uri u;        
 Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
 picMessageIntent.setType("image/jpeg");
 File downloadedPic = new File(Environment.getExternalStorageDirectory(), strFileName + ".jpg");// Art_Nature           
 if(downloadedPic.exists())
    {
      Uri u1 = Uri.fromFile(downloadedPic);
      uris.add(u1);
      picMessageIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      startActivity(picMessageIntent);
    }

1 个答案:

答案 0 :(得分:4)

这是可以帮助你的东西。确保以适当的方式拼写图像文件路径。不要忘记“/”分隔符(尝试获取路径的日志)。另外,请确保该文件存在。

/** ATTACHING IMAGE TO EMAIL AND SENDING EMAIL  */
        Button b1 = (Button)findViewById(R.id.finalsectionsubmit);
        b1.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
//        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailSignature);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, toSenders);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subjectText);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, messageText+"\n\n"+emailSignature); 

        emailIntent.setType("image/jpeg");
        File bitmapFile = new File(Environment.getExternalStorageDirectory()+
            "/"+FOLDER_NAME+"/picture.jpg");
        myUri = Uri.fromFile(bitmapFile);
        emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);


        startActivity(Intent.createChooser(emailIntent, "Send your email in:"));
        eraseContent();
        sentMode = true;
      }
    });