问题附件编程方式发送电子邮件 [英] problem sending an email with an attachment programmatically

查看:181
本文介绍了问题附件编程方式发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的想使用本地电子邮件客户端在Android上发送电子邮件 手机。

i`m trying to send an email using native email client on android phone.

我曾尝试以下方法来附件添加到邮件...

I have tried following ways to add an attachment to the mail...

方法 - 1

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/abc.jpg"));

方法2

发送图像作为主体内容---

Sending the image as body content---

sendIntent.putExtra(Intent.EXTRA_TEXT, "<HTML><BODY><b><IMG**SRC=
\"data:image/jpeg;base64," + <imagepath> + "\"**alt = \"**pleaseview this
image\"/></b></BODY></HTML>");

我可以成功地手动附加图像,但是当我试图 附加和它编程方式发送邮件发送无 attachement。

i can successfully attach the image manually but when i tried to attach and send it programmatically the mail was sent without attachement.

请让我知道如果有一种方法来发送附件 编程使用的电子邮件客户端

Please let me know if there is a way to send an attachment programmatically by using email client

推荐答案

我觉得你的问题是,你不把正确的文件路径。

I think your problem is that you are not putting right the file path.

对我来说,以下工作:

Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Pictures/
image.jpg"));
startActivity(i);

请注意,文件的路径有3个/,前两个为文件://,头,另外因为SD卡dir是文件系统,这是/在Linux的根目录里面。

Note that file path has 3 "/", the first two for the "file://" header, the other because sdcard dir is inside the root of the filesystem, which is "/" in linux.

这篇关于问题附件编程方式发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆