Adding a css template to java mail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • popprem
    New Member
    • Nov 2008
    • 19

    Adding a css template to java mail

    Hi,

    I'm trying to send mail from our application using java mail api. There is
    a .css file which i need to use for it. How can i do it?????

    The problems i faced are :
    I tried to get the .css file through Datasource and add it to the body
    part with a content id and tried to call it from the html code using cid.
    And i found that the .css file is attached to the mail, not templated.
    Also inside the .css file i used cid
    to access an image and it also came as an attachment. I need to know
    how to add a .css template to the mail????

    I can send the code if needed.

    Thanks in advance.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I think you're going to have to read the contents of the CSS file and add it to the <head><style>.. .</style></head> section of the HTML that makes up the body of your email.

    I haven't tried this myself but I think that would be how it would have to go.

    -Frinny

    Comment

    • awinash03
      New Member
      • Feb 2012
      • 1

      #3
      Its been around a week.I have been working on this java mail .even I tried a lot to use css file in my html file in every possible way.I found Two possible way of doing it.
      1) you can attach the CSS file as an attachement and in HTML you can reference it using "cid:style.css" .
      2)you can include the whole CSS script in body section of HTML file.

      In both cases,for some clients it will work fine and for some it wont.I tried to use 2nd case.HTML page got displayed fine in yahoo mail,but in gmail it didn't work.
      If your CSS is not much complicated then it may work(in gmail too).but it will be headache after all.

      Later I came to know that some clients like gmail avoid the attached css file .It also avoids the content between head section in HTML file. so the best thing is try to avoid using css file.use inline style.
      By the way, its just matter of one html page.so you can avoid..:)

      Comment

      Working...