当前位置: 首页 > 知识库问答 >
问题:

如何在Android上发送电子邮件附件

宗啸
2023-03-14

我已经成功创建了PDF文件,它存储在内部storage/app_name/files/xyz.PDF中,现在我只想在Gmail的附件中分享那个PDF......更新:在调试器中获取错误“源代码与字节码不匹配”

Here is the code:     
File filelocation = new 
File("/storage/emulated/0/Android/data/com.example.app_name/files/s.pdf");
Uri path = Uri.fromFile(filelocation); 
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));

正在获取异常文件:///storage/emulated/0/storage/emulated/0/android/data/com.example.app_name/files/s.pdf通过clipdata.item.geturi()在应用程序之外公开

共有1个答案

荆梓
2023-03-14

使用下面的代码在电子邮件中发送文件。

String filename="xyz.pdf"; 
File filelocation = new File(Internal Storage/app_name/files/);
Uri path = Uri.fromFile(filelocation); 
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
 类似资料:
  • 问题内容: 我在理解如何使用Python通过电子邮件发送附件时遇到问题。我已成功通过电子邮件将简单消息通过电子邮件发送。有人可以在电子邮件中说明如何发送附件。我知道在线上还有其他帖子,但是作为Python初学者,我很难理解它们。 问题答案: 这是另一个:

  • 问题内容: 我正在使用sendgrid发送电子邮件,并且使用以下代码可以正常工作,但没有附件。 但是我需要发送附件,因此我搜索了github源和Web文档API,由于某种原因,没有javadocs,但是有一个示例GitHub sendgrid, 所以我一直在尝试直到它起作用为止,我缩小了一些异常和响应代码,起初我是被禁止的未经授权,最好是响应202,表示有效且已排队(在此处检查),这是我的代码发送

  • 可能重复: 如何从我的Android应用程序发送电子邮件? 我正在创建一个main。xml 如何在android中发送电子邮件。但必须是固定id(例如:myid@example.com) 我有main。xml

  • 问题内容: 我找到了这个库,并设法以空电子邮件发送附件,但没有将文本和附件组合在一起。 https://github.com/sloonz/go-mime-message 如何做呢? 问题答案: 我最终自己实现了它:https : //github.com/scorredoira/email 用法很简单:

  • 我已经看到了一些关于堆栈溢出的类似问题,但我找不到解决这些问题的方法。 我正在尝试使用Python发送一封带有。pdf附件。当我在gmail上查看邮件时,它似乎工作正常。但是当我通过苹果的邮件程序查看邮件时,我没有看到附件。知道是什么原因吗? 我的代码如下。很多都是从stack overflow上的不同位置复制的,所以我不完全理解每个部分在做什么,但它似乎(大部分)起作用: 我不确定它是否相关,但

  • 我在网上看到了很多代码,但它们似乎都遇到了问题。 使用以下功能创建并保存文件: 然而,当运行下面的代码来发送文件时,我一直遇到问题,并建议使用此链接的所有答案https://stackoverflow.com/questions/48117511/exposed-beyond-app-through-clipdata-item-geturi,当打开Gmail时,它说无法附加文件 如果有任何方法可以