Tutorials Scripts Free Q&A Books


 







:שמתשמ
:המסיס
  

0 :םויה תוסינכ
53 :שדוחה תוסינכ
1 :ןיילנוא םישלוג
רחא PHP CGI ASP JavaScript Cold Fusion JSP

JSPב םיטפירקס


ליימרופ
םיזיע בלוח :רבחמה םש
http://www.builder.co.il :תיב-רתא

:תורעה\תויחנה
ףדל אוה ינשה דוקהו ספוטה לש ףדל דוקה אוה ןושארה דוקה
.ליימיאה תא חלושש

:דוק

First File
############
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title></title>
</head>

<body bgcolor="#008080">

<p align="center"><br>
<font color="#80FF80" size="5">How to Send Mail using JSP</font></p>

<form action="formmail.jsp" method="POST">
<div align="center"><center><table border="0" cellpadding="2"
cellspacing="0">
<tr>
<td bgcolor="#0000FF">&nbsp;</td>
<td align="center" bgcolor="#0000FF"><font
color="#80FF00" face="Trebuchet MS"><u>Form Mail
Sending Example</u></font></td>
<td align="center" bgcolor="#0000FF"><font
color="#80FF00" face="Trebuchet MS"><u>Examples</u></font></td>
</tr>
<tr>
<td bgcolor="#000080"><font color="#00FFFF"
face="Trebuchet MS">From</font></td>
<td bgcolor="#008080"><font face="Trebuchet MS"><input
type="text" size="20" name="from"></font></td>
<td bgcolor="#008080"><font color="#80FF00"
face="Trebuchet MS">joe@acme.com</font></td>
</tr>
<tr>
<td bgcolor="#000080"><font color="#00FFFF"
face="Trebuchet MS">To</font></td>
<td bgcolor="#008080"><font face="Trebuchet MS"><input
type="text" size="30" name="to"></font></td>
<td bgcolor="#008080"><font color="#80FF00"
face="Trebuchet MS">mary@acme.com</font></td>
</tr>
<tr>
<td bgcolor="#000080"><font color="#00FFFF"
face="Trebuchet MS">Subject</font></td>
<td bgcolor="#008080"><font face="Trebuchet MS"><input
type="text" size="40" name="subject"></font></td>
<td bgcolor="#008080"><font color="#80FF00"
face="Trebuchet MS">Hi There!</font></td>
</tr>
<tr>
<td bgcolor="#000080"><font color="#00FFFF"
face="Trebuchet MS">Use Server</font></td>
<td bgcolor="#008080"><font face="Trebuchet MS"><input
type="text" size="40" name="server" value="localhost"></font></td>
<td bgcolor="#008080"><font color="#80FF00"
face="Trebuchet MS">acme.com</font></td>
</tr>
<tr>
<td valign="top" bgcolor="#000080"><font
color="#00FFFF" face="Trebuchet MS">Msg Body</font></td>
<td bgcolor="#008080"><textarea name="msgbody"
rows="20" cols="38"></textarea></td>
<td bgcolor="#008080">&nbsp;</td>
</tr>
<tr>
<td bgcolor="#008080">&nbsp;</td>
<td align="center" bgcolor="#008080"><input
type="submit" name="B1" value="Submit"></td>
<td bgcolor="#008080">&nbsp;</td>
</tr>
</table>
</center></div>
</form>
</body>
</html>

Second File
############

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

 

הרזח >>
...