This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "sending email with HTML tags" Watch "sending email with HTML tags" New topic
Author

sending email with HTML tags

George Carlson
Greenhorn

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
Hi
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
Greenhorn

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
Greenhorn

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, java.io.IOException
{
// Set the content type of the response
resp.setContentType("text/html");
resp.setHeader("Expires", "Tues, 01 Jan 1980 00:00:00 GMT");
// Create a PrintWriter to write the response
java.io.PrintWriter out =
new java.io.PrintWriter(resp.getOutputStream());

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!
thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sending email with HTML tags
 
Similar Threads
How do I put a hyperlink in a programatically sent email message?
Convert Html Email to Plain Text
Sending an html document with embedded images
Jsp to html
e-mail sender!