• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding a css template to java mail

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need it to be embedded. Check out Apache Common's Email with its HtmlEmail class. It's Javadoc page shows how to embed an image; a CSS file should work the same.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you expecting the mail client which displays your mail to use your CSS file? Don't be too disappointed if it doesn't do that, because I don't think it will. Do you have a reason to believe that mail clients will use CSS from the message? Have you seen messages which work that way?

(If you have, just take a look at how they are structured and then construct yours in the same way.)
 
Prasath Premkumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks for the replies.

It is possible to send Html mails through java mail api, and i have seen few tutorials on embedding images too. What i'm trying to do is write a html message and in <link> tag to embed style sheet. If the email client is capable of displaying Html content, it should be able to render the <link> tag as well, isnt it?? (since it is a html component). And within the style sheet i have reference to images too.

Normally to embed images, we create a bodypart, construct a datasource and set datahandler to the bodypart with the datasource and add the bodypart to the message setting up a content id which can be used to reference the image through tag. But it doesn't work as i thought, instead of embedding the .css file , it sends it as attachment. So i want to know whether are there any possible ways to do this?? I have seen templated mails sent as notifications from few sites like American express Credit card statements, but cannot get the source of those stuff. Also the tutorials says that in this way we can embed images, but still i get them as attachments too.

Are there any other ways to send templated mails using java mail api with embedded images???

Thanks.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no guarantee that an e-mail client will implement all of HTML. It's just an assumption on your part that they might be able to use your CSS files to prettify the HTML. It's quite possible that they don't. Or that many of them don't.

But if you've actually seen that in action, then just look at the messages which use the feature. I don't understand what you mean by "cannot get the source". E-mail messages don't have "source". One of the example programs which comes with the JavaMail download can be used to break a message into its parts and dump them to the console.

I'm not sure what you mean by "templated" mails either. That isn't an e-mail concept that I'm aware of. You can certainly use a template to generate data for an e-mail message but the mail clients don't know that you did that and wouldn't care anyway.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Outlook allows you to receive emails with html content. I don't know what difference it makes, but if you open an html file in internet explorer (i used IE 7), then do a select all of the page, copy it, paste it into outlook and send the mail, the recipient will have colors properly displayed.

If the recipient rightclick on the email body and view source, you can see it's html and has style sheet contents.

(I used this html from "view source" to send the emails afterward and it worked )
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Awinash Kumar wrote:2)you can include the whole CSS script in body section of HTML file.


It should go in the head section, not the body.
 
Awinash Kumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Rob Spoor :: Yeah!! My mistake......it should be "head section". By the way Thank You for pointing it out..
 
reply
    Bookmark Topic Watch Topic
  • New Topic