Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sending email with HTML tags

 
George Carlson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic