电子邮件中的附件

发布于 2025-01-06 20:31:11 字数 246 浏览 2 评论 0原文

我正在开发一个需要向某人发送电子邮件的应用程序。除了附件之外,一切正常。这是该附件的代码片段

 emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(  "file://"+Environment.getExternalStorageDirectory()+""+attach));

,是我通过手机浏览获得的文件。 但附件未发送,请帮忙。

谢谢

I am developing an app which requires to send email to a person. Everything works fine except the attachment. And here is the piece of code for that

 emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(  "file://"+Environment.getExternalStorageDirectory()+""+attach));

attach is the file i got by browsing in the phone.
But the attachment is not being sent Please Help.

Thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦巷 2025-01-13 20:31:11

根据我的博客文章这里

在 Android 上创建邮件,用户可以使用他的应用程序发送该邮件
选择在网络上广泛传播。但这不是附加文件的方式
将通过 googlemail 发送。

这里的问题是 gmail 应用程序只想发送以下文件
位于SD卡上

意图邮件 = new Intent(android.content.Intent.ACTION_SEND);
mail.setType(“应用程序/八位字节流”);
mail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"[电子邮件]受保护]"});
mail.putExtra(android.content.Intent.EXTRA_SUBJECT, "主题");
mail.putExtra(android.content.Intent.EXTRA_TEXT, "消息");
mail.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/file.txt"));
PrefAct.startActivity(Intent.createChooser(mail, "通过...发送邮件"));

如上所述,当用户发送邮件时,gmail 会拒绝您的附件
当文件不在外部存储上时。

According to my blogpost found here:

Creating a mail on Android which the user may send with the app of his
choice is widely spread on the net. But it isn't how you attach a file
which will be send by googlemail.

The problem here is that the gmail app only want to send files which
are located on the sdcard

Intent mail = new Intent(android.content.Intent.ACTION_SEND);
mail.setType("application/octet-stream");
mail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"[email protected]"});
mail.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
mail.putExtra(android.content.Intent.EXTRA_TEXT, "Message");
mail.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/file.txt"));
PrefAct.startActivity(Intent.createChooser(mail, "Send mail via..."));

As said gmail will refuse your attachment when the user sends the mail
when the file isn't located on the ExternalStorage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文