0

I am trying to apply, some styles in HTML. like positioning the content etc.

I can over lay the text on the image, using the auto code generated by bulletproof website. but cannot apply the styles on the text.

I have following snippet of HTML in email:

Here's the server code for creating email:

MimeMultipart mimeMultipart = new MimeMultipart("related");
MimeBodyPart textBodyPart = new MimeBodyPart();
mimeMultipart = new MimeMultipart("related");
String cid = ContentIdGenerator.getContentId();
textBodyPart.setText(messageBody, "US-ASCII", "html");
mimeMultipart.addBodyPart(textBodyPart);
imagePart.attachFile(file);

imagePart.setContentID("<" + cid + ">");
mimeMultipart.addBodyPart(imagePart);

 msg.setContent(mimeMultipart);
  Transport.send(msg);

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns:v="urn:schemas-microsoft-com:vml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
 </head>
 <body>
  <table cellpadding="0" cellspacing="0" border="0" width="100%">
   <tr>
    <td background="cid:random number.net"
     style="background-repeat:no-repeat;" valign="top">      <!--[if gte mso 9]><v:rect xmlns:v='urn:schemas-microsoft-com:vml' fill='true' 
      stroke='false' style='mso-width-percent:1000;'> <v:fill type='frame' src='cid:ransomnumbernet' 
      style='background-repeat:no-repeat;' /><v:textbox style='mso-fit-shape-to-text:true' 
      inset='0,0,0,0'><![endif] -->
     <div style="margin-left: 2cm;">
      <br>
       <br>
        <br>
         <br>
          <br>
           <br>
            <br>
             <br>
              <br>
               <br>
                <br>
                 <br>
                  <br>
                   <br>
                    <br>
                     <p>Thank you for your order. Your order information
                      is:</p>
                     <br>
                      <table width="50%" colspan="2">
                       <tbody>
                        <tr>
                         <td width="30%" align="left">order</td>
                         <td width="70%" align="left">XXXX</td>
                        </tr>
                        <tr>
                        
                       </tbody>
                      </table>
                      <table width="50%" colspan="2">
                       <tbody>
                        <tr>
                         <td width="30%" align="left">Name</td>
                         <td width="70%" align="left">temp</td>
                        </tr>
                        <tr>
                         <td width="30%" align="left">Phone</td>
                         <td width="70%" align="left">555-555-5555</td>
                        </tr>
                       </tbody>
                      </table>
     </div><!--[if gte mso 9]> </v:textbox></v:rect><![endif] -->
    </td>
   </tr>
  </table>
 </body>
</html>

but the styles don't apply in the email.

Thanks in advance for your time.

kumar
  • 31
  • 4
  • 2
    Could you reformat your code? There is tons on a single line and it makes it hard to read – last10seconds Aug 07 '15 at 17:47
  • 1
    possible duplicate of [How to embed images in email](http://stackoverflow.com/questions/4312687/how-to-embed-images-in-email) – PaulProgrammer Aug 07 '15 at 17:48
  • Note that the image source for backgrounds is something like `cid: ...`. It looks like some tool is outputting the html for you. In an email, you need to include the image as part of the message in a `multipart/mime` setup. See the noted duplicate. – PaulProgrammer Aug 07 '15 at 17:50
  • @Rick code reformatted. – kumar Aug 07 '15 at 18:10
  • @PaulProgrammer yes, i have included the image using cid, i can see the image in the email sent, with text over it, but i cannot apply styles using inline css or by declaring – kumar Aug 07 '15 at 18:12
  • Your HTML needs a properly opened/closed HEAD and BODY. – Maximillian Laumeister Aug 07 '15 at 18:16
  • @MaximillianLaumeister i did add the neccesary tags, no use. updated the code. – kumar Aug 07 '15 at 18:33
  • You are closing ` – Stephen P Aug 07 '15 at 22:25
  • @StephenP I made the changes you mentioned, but still dont see style mentioned in div is not working.updated the html generated by the email client. appreciate your thoughts, thanks in advance. – kumar Aug 12 '15 at 17:14
  • @MaximillianLaumeister I have added neccasary tags (updated above code), and used left margin, still no css effect on email body. aprreciate your thoughts, Thanks in advance. – kumar Aug 12 '15 at 17:18
  • @sboesch I have seen your post on HTML formatting in email (http://stackoverflow.com/questions/28363580/simple-html-email-basic-css-styles-being-stripped) , do you think its the same problem here, but i dont see the space like in other example. Appreciate your thoughts. Thanks in advance. – kumar Aug 12 '15 at 19:19

1 Answers1

0

Close out your <head> tag

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
   </head>
Adam Buchanan Smith
  • 9,422
  • 5
  • 19
  • 39
  • I have added head and body tags with meta info, still dont see the styles effective am using outlook 10 to test. – kumar Aug 07 '15 at 18:33