简体   繁体   English

使用Android在Mail和Gmail中获取电子邮件的多个附件

[英]Getting multiple attachments to email in both Mail and Gmail with Android

I can get both Mail and Gmail to attach multiple csv files to an email. 我可以同时使用Mail和Gmail来将多个csv文件附加到电子邮件中。

When sent via Mail all the attachments are delivered. 通过邮件发送时, 所有附件均已交付。
When sent by Gmail none of the attachments are delivered. 由Gmail发送时, 没有附件被发送。

I have read the documentation Send Binary Content . 我已经阅读了文档发送二进制内容 I have searched but only found a solution for Gmail that does not work with Mail. 我已经搜索过,但是只找到了不适用于Mail的Gmail解决方案。 Mail seems happy with just about any approach. Mail几乎对任何方法都满意。 Gmail just doesn't want to play. Gmail只是不想播放。

Has anyone found a solution for sending multiple attachments that works with both Mail and Gmail? 有没有人找到一种解决方案,该解决方案可以发送适用于Mail和Gmail的多个附件?

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
String subject = context.getString(R.string.export_data_email_header);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.setType("text/csv");

ArrayList<Uri> uris = new ArrayList<Uri>();
if (diariesSelected) uris.add(Uri.fromFile(context.getFileStreamPath("diaries.csv")));
...
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

context.startActivity(emailIntent);

And the code used to create the file 和用于创建文件的代码

 FileOutputStream fos = context.openFileOutput(path, Context.MODE_WORLD_READABLE);
 OutputStreamWriter writer = new OutputStreamWriter(fos);
 writer.append(builder.toString());
 writer.close();
 fos.close();

The following code is a snippet from one of my apps. 以下代码是我的一个应用程序的摘录。 As far as I remember, it works with GMail and Mail (Can't verify it at the moment.). 据我所知,它适用于GMail和Mail(目前无法验证。)。 It looks basically like your solution, but with a few little differences. 它看起来基本上像您的解决方案,但有一些区别。 Maybe one of them is what you are looking for. 也许其中之一就是您要寻找的东西。 :) :)

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "address@mail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "The subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "The actual message");

ArrayList<Uri> attachmentUris = new ArrayList<Uri>();

for (File attachment : attachments) {
    attachmentUris.add(Uri.fromFile(attachment));
}

emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachmentUris);

startActivity(emailIntent);

Here you can get detail information https://stackoverflow.com/a/18225100/942224 在这里您可以获取详细信息https://stackoverflow.com/a/18225100/942224

by using below code i am attaching image file in gmail or Mail.... hope it will help you 通过使用以下代码,我将图像文件附加在gmail或Mail中。...希望对您有所帮助

Intent ei = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ei.setType("plain/text");
        ei.putExtra(Intent.EXTRA_EMAIL, new String[] {"email id"});
        ei.putExtra(Intent.EXTRA_SUBJECT, "That one works");

        ArrayList<String> fileList = new ArrayList<String>();
        fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg");
        fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/certificate.jpg");
        fileList.add(Environment.getExternalStorageDirectory()+"/foldername/Aa.pdf");

        ArrayList<Uri> uris = new ArrayList<Uri>();
        //convert from paths to Android friendly Parcelable Uri's

        for (int i=0;i<fileList.size();i++)
        {
            File fileIn = new File(fileList.get(i));
            Uri u = Uri.fromFile(fileIn);
            uris.add(u);
        }

        ei.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        startActivityForResult(Intent.createChooser(ei, "Sending multiple attachment"), 12345);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM