You can build the html as a String, then convert the String to a byte array.
Create a File, get a FileOutputStream and pass the byte[] to the stream. Now
you have a file you can attach to an email. This is whole different animal
but take a look at javax.mail api. We recently did exactly this- if there is
a specific part of the email you have trouble with let me know and I can
send you the code. I am sure that there is a better way to generate the html
(i.e. using html generation objects), but this is quick and dirty and worked
fine for us...
The following is some code from an Action class:
String message = "<html> ... some html ... </html>";
String filename =
this.getServlet().getServletContext().getRealPath("/temp/myFile.html");
File file = new File(filename);
byte[] byteMe = message.getBytes();
FileOutputStream fos = new FileOutputStream(file);
fos.write(byteMe);
fos.close();
-----Original Message-----
From: Natra, Uday [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 27, 2001 2:09 PM
To: '[EMAIL PROTECTED]'
Subject: How to generate html dynamically and write it to a file?
Hi All,
I have this scenario.
When the user clicks a button on a html page, I need to do some back ground
processing which involves generation of some Html, based on the values in
the database and then the generated html need to be saved as a file.
Ofcourse I think I know how to e-mail that file once I get it. If any one
has implemented this or have any ideas please let me know.
Thanks,
Uday.