<html>
<!--
Copyright (c) Object Productions, Inc.
All Rights Reserved Worldwide --
License Hereby Granted for Individual Non Commercial Use
see www.jsptutorial.com for more information
Author: Jordan Bortz, Email: JordanB@surfnetusa.com
-->
<body bgcolor="white">
<font size=5 color="black">
<%@ page import="javax.servlet.http.HttpUtils" %>
<%@ page import="java.util.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.io.*" %>
<%@ page import= "sun.net.smtp.SmtpClient" %>
<%
String from,to,subject,msgbody,serverName;
try
{
from = request.getParameterValues("from")[0];
to = request.getParameterValues("to")[0];
subject = request.getParameterValues("subject")[0];
msgbody = request.getParameterValues("msgbody")[0];
serverName = request.getParameterValues("server")[0];
}
catch (Exception e) // Generally Speaking, an Error getting one of these
// Values means that it wasnt passed in; inform the user
{
out.println("You must call this JSP from this ");
out.println("<A href=\"FormMail.htm\"> form</A>.<BR>");
out.flush();return;
}
%>
Hold On A Moment while I try to Send Your Mail... <BR>
<%
out.flush();
// Here are the real guts of the mail sending
try
{
sun.net.smtp.SmtpClient sm = new sun.net.smtp.SmtpClient(serverName);
sm.from(from);
sm.to(to);
PrintStream msg = sm.startMessage();
msg.println("To: "); // Note dont use + for Performance
msg.println(to);
msg.println("Subject: ");
msg.println(subject);
msg.println();
msg.println(msgbody);
msg.println("==============");
msg.print("This mail brought to you by JSP MAIL..from a user at IP ");
msg.println(request.getRemoteHost());
sm.closeServer();
out.println("Your Mail Has Been Sent!");
}
catch (Exception e)
{
out.println("The mail couldn't be sent, probably because the mailhost wasnt set correctly.<BR> ");
out.println("The error message I am getting is: ");
out.println(e.getMessage());
}
%>
<BR>
<BR>
<A HREF="FormMail.htm">Click here to send another!</A>
|