Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Servlets and the fly likes sending email with HTML tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "sending email with HTML tags" Watch "sending email with HTML tags" New topic

sending email with HTML tags

George Carlson

Joined: Aug 24, 2000
Posts: 15
Hello, I have created a class that sends out email. I need to put html tags inside the e-mail. Do I have to do something special with the servlet to allow the recipients to be able to receive this as an HTML document instead of plain text with a bunch of tags around it or do I need to do something special with the e-mail??
Thanks in advance.
Srividya Shiv
Ranch Hand

Joined: Jul 20, 2000
Posts: 31
U cannot directly embed HTML tags in the message in java mail.u must first convert html content types into byte source and then in the mimebodypart use setDataHandler as :
mimebodypart.setDataHandler(new DataHandler(new ByteArrayDataSource(url,"text/html")));
where url is the string that contains html tags
hope u are able follow this.i have some code for this,but its too lengthy to attach here.
George Carlson

Joined: Aug 24, 2000
Posts: 15
Thanks for your help. I did figure out how to do it about an hour before your reply, but I used the same methods.
Thanks anyway.
joe script

Joined: May 05, 2003
Posts: 11
i do not understand how to use this code...
i am doing the same thing, sending out an e-mail (from form data) that i want to format with HTML tags..
i use this to spit out the HTML to a browser:
public class foodConfirm extends HttpServlet
* <p>Performs the HTTP POST operation
* @param req The request from the client
* @param resp The response from the servlet

public void doPost(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
// Set the content type of the response
resp.setHeader("Expires", "Tues, 01 Jan 1980 00:00:00 GMT");
// Create a PrintWriter to write the response out =

But this doesn't do the trick for e-mail.
The reply above says to put my string in the 'url' part, but i am not sure what that means..all the data needs to be enclosed by <html></html>.
if anyone can help, i'd greatly appreciate it!
I agree. Here's the link:
subject: sending email with HTML tags
jQuery in Action, 3rd edition