Vivek Vardhan Vivek Vardhan - 8 months ago 40
HTML Question

Some CSS styles not applied in html when it as a mail using javax mail

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");

Multipart multipart = new MimeMultipart();
if (body != null) {
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(body, "text/html;charset=utf-8");


And the html body generated was

<style type="text/css">

#content ul li{
display:inline !important;
padding: 7px;
margin-right: 4px;
font-style: italic;


<font face ="Arial" size=4> <U>DESCRIPTION</U>:Test </font><br/><br/>
<div id="content">
<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>


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


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!):

        <font face="Arial" size=4><U>DESCRIPTION</U>:Test</font>

Then you can style the table/cells using inline CSS.