如何在android中发送html内容的邮件?

时间:2012-10-30 05:05:08

标签: android email

这是我的html内容,我有一个按钮,点击按钮我必须发送邮件,但邮件内容(如正文,主题)将取自html内容。

Html内容:

@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
<title>Untitled Document</title>
<style>.reservation { }.reservation table {}.reservation tr { background-color: #F6F2E7; }.reservation th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #F6F2E7; background-color: #302824; padding: 5px; text-align:left; }.reservation td { padding-top: 3px; padding-right: 5px; padding-bottom: 3px; padding-left: 5px; border-bottom: 1px solid #DFDBD1; color: #443D37; font-family: Arial, Helvetica, sans-serif; font-size: 12px; }.reservation td strong { font-weight: bold; padding-right:10px; }.reservation td span { font-weight: normal; }
</style>
</head>
<body>
<div style=\"width:300px; margin:auto;\"><div class=\"reservation\">  
<table width=\"300px\" cellpadding=\"0\" cellspacing=\"0\">  
<tr>   <th width=\"130px\">Reservation </th>  
<th> </th> </tr>   
<tr> <td>     <strong>%@ :</strong>  </td> 
<td>  <span>%@</span>        </td>    
</tr>  <tr> <td>     <strong>%@ :</strong>  </td> 
<td>  <span>%@</span>        </td>    </tr>   
<tr> <td>     <strong>%@ :</strong>  </td> <td> <span>%@</span>        </td>    </tr>    
<tr> <td>     <strong>%@ :</strong> </td> 
<td>   <span>%@</span>        </td>    </tr>  
</table>
</div>
</div>
</body>
</html>

3 个答案:

答案 0 :(得分:3)

据我所知,android不支持直接用于HTML内容的CSS标签。它支持带有phonegap的CSS。

它只支持几个HTML标记:

<a> (supports attribute "href")
<b>
<big>
<blockquote>
<br>
<cite>
<dfn>
<div>
<em>
<font> (supports attributes "color" and "face")
<i>
<img> (supports attribute "src". Note: you have to include an ImageGetter to handle retrieving a Drawable for this tag)
<p>
<small>
<strong>
<sub>
<sup>
<tt>
<u>

要在代码中使用HTML,您可以使用Html.fromHtml("html data")

答案 1 :(得分:0)

通过邮件发送Html内容您必须使用Html.fromHtml("html data").

此处示例代码..

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
        emailIntent.setType("text/html");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
            emailTo);
        emailIntent.putExtra(android.content.Intent.EXTRA_CC, 
                emailCc);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
                Html.fromHtml(subject));
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
                Html.fromHtml(emailText));

   this.startActivity(Intent.createChooser(emailIntent, "email"));

AppMobiGurmeet说得对。 Android仅支持一些Tag ..

有关更多信息,请查看以下链接..

Link1

Link2

答案 2 :(得分:0)

使用HTML标记并分配到字符串中。并使用Html.fromHtml(body)进行访问。

String body= first_name
                    + " "
                    + last_name
                    + " sent a message using ."
                    + "<br><br><br>Submitted on :" + date + " "+ time + "<br>"
                    + "Submitted by user:"+ first_name + " " + last_name + "<br>"
                    + "Address :" + Address + "<br>"
                    + "Contact No :"+ mobile + "<br>"

                    + "Comments :" + comment;


            Intent email = new Intent(Intent.ACTION_SEND);
            email.putExtra(Intent.EXTRA_EMAIL,
                    new String[] { "emailID"});



            email.putExtra(Intent.EXTRA_SUBJECT,
                    "Form submission from:");
            email.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(body));
            email.setType("message/rfc822");

            startActivityForResult(
                    Intent.createChooser(email, "Choose an Email client :"),
                    MY_REQUEST_CODE);