简体   繁体   English

如何在Android中发送HTML电子邮件?

[英]how to send html email in android?

Hi I am making an app in which I am sending an email to a specific address 嗨,我正在制作一个应用,其中我正在向特定地址发送电子邮件

This email is a html email with table and images and all... 这封电子邮件是HTML电子邮件,其中包含表格和图片以及所有... 像这样

Is I have tried to add Html.fromhtml() but it keeps saying type mismatch needed string found spanned.... 我是否尝试添加Html.fromhtml()但一直说类型不匹配需要跨过的字符串。...

If you need any of my code please comment 如果您需要我的任何代码,请发表评论

Please suggest any tutorial if you have in mind 如果您有想法,请建议任何教程

EDIT I forgot to mention I am sending mail using javax.mail library I am not using Intents I tried to use Html.tohtml(Spanned text) its giving the message of type mismatch cant convert String to spannedtext 编辑我忘了提到我正在使用javax.mail库发送邮件我没有在使用Intents我试图使用Html.tohtml(Spanned text)其给出类型不匹配的消息,无法将String转换为spannedtext

I have no idea whats happening 我不知道发生了什么

I am receiving the html data in my mail if i just go with it 如果我随身携带邮件,我将收到html数据

UPDATE I am fetching the content from a string resource and this is what I am getting as result 更新我正在从字符串资源中获取内容,这就是我得到的结果

$message = ' For Support enquiry@makeintern.comContact Form Enquiry ! $ message ='寻求支持enquiry@makeintern.com联系表格查询! Name: :'.$name.'Email: :'.$email.'Contact: :'.$mobile.'Message: :'.$message.'Date-Time: :'.$current_date.' 姓名::'。$ name。'电子邮件::'。$ email。'联系人::'。$ mobile。'消息::'。$ message。'日期时间::'。$ current_date。'

Thanks and Regards MakeIntern Team Account Manager - MakeIntern Cell www.makeintern.com enquiry@makeintern.com 感谢和问候MakeIntern团队客户经理-MakeIntern单元www.makeintern.com enquiry@makeintern.com

If any query Please call us on : 011-45544188  www.makeintern.com | 如有任何疑问,请致电:011-45544188www.makeintern.com | enquiry@makeintern.com  enquiry@makeintern.com

from--- 从 - -

<string name="email">$message = \'&lt;center&gt;
   &lt;table width="100%" cellpadding="0" cellspacing="0"&gt;
   &lt;tr&gt;
  &lt;td align="center" bgcolor="#FFFFFF"&gt;
    &lt;table width="620px" cellpadding="0" cellspacing="0"&gt;
    &lt;tr&gt;
        &lt;td width="400px"  bgcolor="#000000"  style="color:#FFFFFF; text-

decoration:none; float:left;font-size:10px;margin: -18px 3px -1px 11px; font-weight:bold; padding:2px; text-decoration:none; padding-left:0px;"&gt;For Support &lt;span style="text-decoration:none; color:#FFFFFF;"&gt;enquiry@makeintern.com&lt;/span&gt;&lt;/td&gt;
&lt;td width="220px" bgcolor="#000000"&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr style="background-color:#737373;"&gt;
&lt;td width="290" align="left" valign="middle"&gt;&lt;a href="http://makeintern.com" target="_blank"&gt;&lt;img src="http://www.makeintern.com/images/makeintern.jpg" width="136" border="0" alt="MakeIntern" style="display:block; padding-left:0px;"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td width="290" align="right" style="text-align:right; font-family:Arial, Segoe UI,Helvetica Neue, Helvetica, sans-serif; font-size:18px; line-height:18px; color:#FFFFFF; font-weight:normal; padding-right:10px;"&gt;Contact Form Enquiry !&lt;br&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height="12px" colspan="2"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="2" align="center" style="line-height:16px; font-family:arial; font-size:12px; color:#888888; text-align:left;"&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;
&lt;tr&gt;
        &lt;td width="200px" style="font-weight:bold;"&gt;Name: &lt;/td&gt;
        &lt;td width="100px"&gt;:&lt;/td&gt;
        &lt;td&gt;\'.$name.\'&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
        &lt;td width="200px" style="font-weight:bold;"&gt;Email: &lt;/td&gt;
        &lt;td width="100px"&gt;:&lt;/td&gt;
        &lt;td&gt;\'.$email.\'&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
        &lt;td width="200px" style="font-weight:bold;"&gt;Contact: &lt;/td&gt;
        &lt;td width="100px"&gt;:&lt;/td&gt;
        &lt;td&gt;\'.$mobile.\'&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
        &lt;td width="200px" style="font-weight:bold;"&gt;Message:  &lt;/td&gt;
        &lt;td width="100px"&gt;:&lt;/td&gt;
        &lt;td&gt;\'.$message.\'&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
        &lt;td width="200px" style="font-weight:bold;"&gt;Date-Time:  &lt;/td&gt;
        &lt;td width="100px"&gt;:&lt;/td&gt;
        &lt;td&gt;\'.$current_date.\'&lt;/td&gt;
        &lt;/tr&gt;


        &lt;/table&gt;

        &lt;br/&gt;&lt;br/&gt;

        Thanks and Regards &lt;br/&gt;
        MakeIntern Team &lt;br/&gt;
        Account Manager - MakeIntern Cell &lt;br/&gt;
        www.makeintern.com&lt;br/&gt;
        enquiry@makeintern.com&lt;br/&gt;&lt;br/&gt;
        &lt;b&gt;If any query Please call us on : 011-45544188&lt;/b&gt;&lt;br/&gt;
        &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
        &lt;td height="12px"&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
        &lt;td colspan="2"&gt;&lt;img src="http://www.myhotbooking.com/images/email-template/bar.png"&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
        &lt;td colspan="2" bgcolor="#737373" height="90px"&gt;
        &lt;table cellpadding="0" cellspacing="0" width="620px"&gt;
        &lt;tr&gt;
        &lt;td height="10px"&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
        &lt;td align="center" style="color:#FFFFFF;" height="20px"&gt;&lt;a href="http://www.makeintern.com/"&gt;www.makeintern.com &lt;/a&gt;| &lt;span style="color:#FFFFFF; text-decoration:none;"&gt;enquiry@makeintern.com&lt;/span&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
        &lt;td align="center" valign="middle"&gt;
        &lt;a href="https://www.facebook.com/makeinterns" target="_blank"&gt;&lt;img src="http://www.myhotbooking.com/images/email-template/icon-facebook.png" width="26" height="26" border="0" alt="Facebook"&gt;&lt;/a&gt;&lt;a href="https://twitter.com/makeintern" target="_blank"&gt;&lt;img src="http://www.myhotbooking.com/images/email-template/icon-twitter.png" width="26" height="26" border="0" alt="Twitter"&gt;&lt;/a&gt;&lt;a href="https://www.linkedin.com/company/makeintern" target="_blank"&gt;&lt;img src="http://www.myhotbooking.com/images/email-template/icon-linkedin.png" width="26" height="26" border="0" alt="Linkedin"&gt;&lt;/a&gt;&lt;a href="https://plus.google.com/+makeintern" target="_blank"&gt;&lt;img src="http://www.myhotbooking.com/images/email-template/icon-google-plus.png" width="26" height="26" border="0" alt="Google+"&gt;&lt;/a&gt;&lt;/td&gt;


        &lt;/tr&gt;
        &lt;tr&gt;
        &lt;td align="center" style="color:#FFFFFF;"&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;/table&gt;
        &lt;/td&gt;
        &lt;/tr&gt;
        &lt;/table&gt;
        &lt;/td&gt;
        &lt;/tr&gt;
        &lt;/table&gt;
        &lt;/center&gt;\'</string>

Thankyou in advance 先感谢您

Have you use this code: 您是否使用过以下代码:

final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
    .append("<p><b>Some Content</b></p>")
    .append("<small><p>More content</p></small>")
    .toString())
);

if not then please try it . 如果没有,请尝试一下。 Hope this will help ! 希望这会有所帮助! Cheers ! 干杯!

UPDATE: 更新:

TextView contentView = (TextView)view.findViewById(R.id.contentPreview);
SpannableString contentText = (SpannableString) contentView.getText();
String htmlEncodedString = Html.toHtml(contentText);
String decodedString = StringEscapeUtils.unescapeHtml4(htmlEncodedString);

Log.e("Content Text",decodedString);

use this to decode and encode 用它来解码和编码

Try Below Code : 尝试以下代码:

Intent sendIntent = new Intent();
 sendIntent.setAction(Intent.ACTION_SEND);
 sendIntent.putExtra(Intent.EXTRA_SUBJECT,getResources().getString(R.string.email_subject));
 sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getResources().getString(R.string.email_text)));
 sendIntent.setType("text/plain");
 startActivity(Intent.createChooser(sendIntent, ""));

string.xml string.xml

<resources>    
    <string name="email_subject">Download App for your smartphone.</string>
    <string name="email_text"><![CDATA[Hey,<br/>I just downloaded App on my Android.<br/>It is a smartphone Manager.This app even lets me book parties,search restaurants.<br/>App is available for Android.<br/>
        Get it now from http://www.exampleapp.com/download]]></string>
</resources>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM