Here is what I use:
// here is a function from my MailUtils class
public boolean formSend(String to, String fromAddress, String
fromPersonal,
String msgSubject, PageContext pc, String templateURL) {
if (templateURL == null || templateURL.equals("")) { return
formSend(to,
msgSubject, pc); }
String httpHost = pc.getRequest().getServerName();
Enumeration params = pc.getRequest().getParameterNames();
String queryString = "?";
if (templateURL.indexOf("?") >= 0) queryString = "&";
while (params.hasMoreElements()) {
String param = (String) params.nextElement();
try {
queryString += param
+ "="
+
URLEncoder.encode(StringUtils.encodeHTML(JSPUtils.getParam(pc,
param)),
"UTF-8") + "&";
} catch (Exception e) {
e.printStackTrace();
}
}
String url = "http://" + httpHost + templateURL + queryString;
try {
// see the Webpage object
Webpage wp = new Webpage(url);
String msgBody = wp.loadPage();
// replace it your own send mail function
send(to, fromAddress, fromPersonal, msgSubject,
msgBody, true);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
// Here is the Webpage
package com.edunet.iwas.util;
import java.net.*;
import java.io.*;
public class Webpage {
private static final String NEW_LINE =
System.getProperty("line.separator");
private String content;
private URL u;
public Webpage(String urlString) throws MalformedURLException {
urlString = StringUtils.replace(urlString, " ", "%20");
this.u = new URL(urlString);
}
public String loadPage() throws IOException {
BufferedReader in = new BufferedReader(
new InputStreamReader(u.openStream()));
String temp;
content = "";
while ((temp = in.readLine()) != null)
content += temp + NEW_LINE;
/* you don't really need the NEW_LINE */
in.close();
return content;
}
public String getContent() {
return content;
}
}
Please use it at your own risk...
Asim
On Tue, 14 Dec 2004 19:15:13 -0300, Gabriel Belingueres
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> How can I take advantage of Tomcat's JSP processing engine to use a
> JSP page as a template for an email?
>
> That is, I want to do something like a page forwarding from a servlet,
> but this forwarding process the JSP page and, instead of send it to
> the browser, it send it by email to somebody.
>
> Thanks in advance,
> Gabriel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]