android - 发送带附件的邮件只适用于 GMail

标签 android email attachment

我正在尝试从我的 Galaxy Note 3 平板电脑发送一封带有附件的邮件。我发送邮件的代码如下所示:

public static void sendMail(Context context, String rc, String subject, String message, File file, String type) {
    Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { rc });
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.putExtra(Intent.EXTRA_TEXT, message);
    Uri uri = Uri.fromFile(file);
    email.putExtra("android.intent.extra.MIME_TYPES", type);
//      email.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
    email.setClassName("com.android.email", "com.android.email.activity.MessageCompose");
    email.putExtra(Intent.EXTRA_STREAM, uri);
    context.startActivity(email);
}

文件保存到外置sdcard。如果我使用 Gmail 应用程序,附件已附加,我可以发送邮件。如果我使用来自 android 的股票电子邮件应用程序,则附件未附加,我不知道为什么。

有人知道为什么会这样吗?我发现了很多问题,如何将文件附加到电子邮件,他们几乎都使用这种附加文件的方式。那么为什么它只适用于 gmail 应用程序呢?

最佳答案

我以前遇到过类似的问题,但是使用这段代码我可以发送一封带有 csv 文件作为附件的电子邮件,使用“myMail”作为客户端。

 Uri exportFile = null;
 exportFile = Uri.fromFile(file);
 Intent emailIntent = new Intent(Intent.ACTION_SEND);

 emailIntent.putExtra(Intent.EXTRA_SUBJECT, "testSubject");
 emailIntent.putExtra(Intent.EXTRA_STREAM, exportFile);
 String aEmailList[] = { "test@test.org" };
 emailIntent.putExtra(Intent.EXTRA_EMAIL, aEmailList);
 emailIntent.setType("message/rfc822");
 emailIntent.putExtra(
     Intent.EXTRA_TEXT,
     emailText
     );       
 startActivityForResult(emailIntent, REQUESTCODE_SENTEMAIL);

关于android - 发送带附件的邮件只适用于 GMail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22456204/

相关文章:

android - 在未经用户同意的情况下处理 Android 中过期的访问 token

android - 输入按键事件在数字输入字段上不起作用?

php - build 中页面的非常简单的订阅表格

android - 如何在 android sdk 中将图像和位置附加到电子邮件?

c# - 在 XML 文件中包含二进制数据

Wpf 按钮数据触发

android - "fragment operation is modifying it in the activity"是什么意思?

android - 使用应用内计费隐藏广告横幅

php - 使用 HTML Mime Mail for PHP 发送电子邮件,但需要通过 Exchange 服务器进行身份验证

attachment - 如何通过对话流(API.AI)获取用户从 Facebook Messenger 机器人发送的图像/附件?