Android - 从应用程序发送电子邮件

发布于 2024-11-02 03:35:19 字数 939 浏览 2 评论 0原文

我在从 Android 应用程序发送电子邮件时遇到问题。它间歇性地工作且不可靠。大多数时候,它停留在发件箱中,处于“正在发送..”状态。

我知道这是一个经常重复的问题,但我再次问它,因为我已经尝试了相当多的代码变体,但它们似乎都不能可靠地工作。一些论坛还说这是 GMail 应用程序的错;我尝试过“刷新发件箱文件夹”和“禁用和启用同步”,但似乎没有任何效果。

这是我的代码:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "emailText");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.setType("application/zip");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/mnt/sdcard/myFolder/myFile.zip")));
startActivity(Intent.createChooser(emailIntent, "send email"));
finish();
  1. 有人可以解释为什么这不起作用吗?
  2. setType() 的值应该是多少?在哪里可以找到可用值的列表?
  3. 是因为我正在尝试发送 .zip 文件吗?如果是这样,其他存档格式也可以吗?

非常感谢您的帮助。

编辑:我怀疑问题出在文件格式(.zip)上。其他文件格式也可以正常工作。我已经放弃了这种方法,转而使用 TCP,用我自己的服务器监听数据。

I am facing problems in sending email from an Android app. It works intermittently and unreliably. Most of the times, it is stuck in Outbox, in 'Sending..' state.

I know this is a oft-repeated question here, but I am asking it again because I have tried quite a few variations in code, and none of them seem to work RELIABLY. Some forums also say that this is GMail app's fault; and I have tried 'refreshing the outbox folder' and 'disabling and enabling sync', but nothing seems to do the trick.

Here is my code:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "emailText");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.setType("application/zip");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/mnt/sdcard/myFolder/myFile.zip")));
startActivity(Intent.createChooser(emailIntent, "send email"));
finish();
  1. Could someone explain why wouldn't this work?
  2. What should be the value for setType()? Where can I find a list of available values?
  3. Is it because I am trying to send a .zip file? If so, would other archive formats work?

Thanks a lot for your help.

EDIT: I suspect that the issue is with file format (.zip). Other file formats work just fine. I have abandoned this approach and gone for TCP with my own server listening for data.

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

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

发布评论

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

评论(1

面犯桃花 2024-11-09 03:35:19

它可能卡在发送状态的原因是因为根据 zip 文件的 SIZE,它必须将其添加到电子邮件中。如果它太大(超过 30 MB),它可能会挂起并被谷歌拒绝,因为谷歌不允许在电子邮件中发送超过 30MB 的内容。这只是一个猜测,但请尝试发送一个小文件,看看是否是这种情况。

The reason why it could be stuck in the sending state is because depending on the SIZE of the zip file, it has to add it to the email.. If its too large (over 30 MB) it might hang and get denied by google, since google does not allow the sending of over 30MB in an email. This is just a guess, but try sending a small file and see if this is the case.

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