问题描述
我试图使用Javax邮件API将格式化的html作为邮件发送。
使用的邮件实用代码是
I am trying to send a formatted html as a mail using Javax mail API.The mail util-code used is
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setHeader("Auto-Submitted", "auto-generated");
message.setReplyTo(InternetAddress.parse(commaSeperatedReplyTo));
Multipart multipart = new MimeMultipart();
if (body != null) {
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(body, "text/html;charset=utf-8");
multipart.addBodyPart(messageBodyPart);
}
message.setContent(multipart);
生成的html正文是
<html>
<body>
<style type="text/css">
#content ul li{
display:inline !important;
float:left;
padding: 7px;
margin-right: 4px;
font-style: italic;
}
</style>
<font face ="Arial" size=4> <U>DESCRIPTION</U>:Test </font><br/><br/>
<div id="content">
<ul>
<li> component_id</li>
<li> component_type_id</li>
<li> name</li>
<li> update_user</li>
<li> update</li>
<li> key</li>
<li> field</li>
</ul>
</div>
</body>
</html>
我在期待它显示为内联,而不是上下。我也在小提琴中测试了生成的html。按预期工作。但是,在邮件中,我将它列为正常列表。为什么内联显示不能用于电子邮件?
I am expecting this to display inline, not up and down. I tested the generated html in fiddle also. Working as expected. But, in the mail, i am getting it as normal list. Why inline display is not working in email?
需要帮助
need help
推荐答案
电子邮件 - 客户往往不遵循标准。像gMail这样的一些客户甚至会忽略< style>
- 块中的CSS声明。 提供了一些关于如何创建HTML电子邮件的很好的资源大多数客户都支持它。
E-mail-clients often do not follow standards. Some clients like gMail even ignore CSS-declarations in a <style>
-block. CampaignMonitor has some great resources on how to create HTML-e-mails that are supported by most clients.
你应该把你的布局转换成这样的样子(使用表格!):
You should convert your layout to something like this (use tables!):
<html>
<body>
<font face="Arial" size=4><U>DESCRIPTION</U>:Test</font>
<br/>
<br/>
<table>
<tr>
<td>component_id</td>
<td>component_type_id</td>
<td>name</td>
<td>update_user</td>
<td>update</td>
<td>key</td>
<td>field</td>
</tr>
</table>
</body>
</html>
然后,您可以使用内联CSS对表/单元格进行样式设置。
Then you can style the table/cells using inline CSS.
这篇关于某些CSS样式在使用javax邮件作为邮件时不适用于html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!