Android的,如何发送HTML电子邮件,并迫使Android的把它通过G-邮件而不是其他应用程序发送? [英] Android, How to send HTML email and force Android to send it through G-Mail not other applications?

查看:152
本文介绍了Android的,如何发送HTML电子邮件,并迫使Android的把它通过G-邮件而不是其他应用程序发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我的应用程序发送电子邮件。我只需要通过G-Mail来发送基于HTML的电子邮件。我发现下面的解决方案,他们每个人都有优点和缺点。

I want to send email through my application. I need to send HTML based email just through G-Mail. I found following solutions that each of them has pros and cons.

1)使用意图(Intent.ACTION_SEND)。这是非常简单的方法,我可以看到我的身体以HTML格式,但问题是,当我点击发送邮件按钮,如此多的应用,如Facebook和Google+弹出哪些是无用的,我不应该在该列表中显示它。这是它的code:

1) Using Intent (Intent.ACTION_SEND). This is very simple way and I can see my body in HTML format but the problem is when I click on "Send email" button, so many applications like Facebook and Google+ pop up which are useless and I shouldn't show it in that list. This is its code:

String html = "<!DOCTYPE html><html><body><a href=\"http://www.w3schools.com\" target=\"_blank\">Visit W3Schools.com!</a>" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"MY EMAIL ADDRESS"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(html));
startActivity(Intent.createChooser(intent, "Send email..."));

2)使用意向(Intent.ACTION_SENDTO)。这样,过滤无用的应用程序,并显示我只是邮件客户端。不过,这并不在Gmail客户端显示我的HTML格式的电子邮件。当我发送电子邮件一些客户展示身体的HTML格式,而其他没有确定HTML和我联系的行为就像纯文本。这code是这样的:

2) Using Intent (Intent.ACTION_SENDTO). This way Filters useless applications and shows me just mail clients. But it doesn't display my email in HTML format in gmail client. When i send the email some clients show the body in HTML format while others doesn't identify HTML and my link behaves like plain text. This code is like:

String html = "<!DOCTYPE html><html><body><a href=\"http://www.w3schools.com\" target=\"_blank\">Visit W3Schools.com!</a>" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:MY EMAIL ADDRESS" + "?subject=subject here" + "&body=" + html;
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));

3)发送邮件使用<一个href="http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a/2033124#2033124">JavaMail API 它增添了非常多的复杂应用程序,我没有到目前为止测试它。

3) Sending mail using JavaMail API which adds so much complexity to application and I didn't test it so far.

你有什么建议吗?我需要一种方法来有第一和第二方面的优势。我需要的时候按钮用户点击它显示的Gmail客户端,我可以告诉他/客户端的主体部分她HTML内容。

What is your suggestion? I need a way to have advantages of first and second ways. I need when user click on button it shows Gmail client and I can show him/her html content in body part of client.

任何建议将AP preciated。谢谢

any suggestion would be appreciated. Thanks

======================

======================

趣谈code 2是错误的。在code是这样的:

Something about code 2 is wrong. The code is like this:

String html = "<!DOCTYPE html><html><body><a href=\"http://www.w3schools.com\" target=\"_blank\">Visit W3Schools.com!</a>" + "<p>If you set the target attribute to \"_blank\", the link will open in a new browser window/tab.</p></body></html>";
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:MY EMAIL ADDRESS" + "?subject=subject here" + "&body=" + Html.fromHtml(html);
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));

推荐答案

请尝试以下 -

Intent shareIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(body));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
startActivity(shareIntent);

这只会present电子邮件应用程序。

This will only present email applications.

这篇关于Android的,如何发送HTML电子邮件,并迫使Android的把它通过G-邮件而不是其他应用程序发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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