<%--
这一段代码是演示jsp发mail 的过程
--%>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
body {
background-color: #006600;
}
.STYLE3 {font-size: x-large; color: #FFFF00; }
-->
</style>
</head>
<%@ page import="sun.net.smtp.SmtpClient"%>
<%@ page import="java.io.*"%>
<%
String to=request.getParameter("to");
String from=request.getParameter("from");
String subject=request.getParameter("subject");
String server=request.getParameter("server");
String content=request.getParameter("content");
if(!to.equals("")&&!from.equals("")&&!subject.equals("")&&!server.equals("")){
try{
SmtpClient mail=new SmtpClient(server);
mail.from(from);
mail.to(to);
PrintStream mailout=mail.startMessage();
mailout.println("From"+from);
mailout.println("To"+to);
mailout.println("Subject"+subject);
mailout.println(content);
mailout.println("\r\n");
mailout.flush();
mailout.close();
mail.closeServer();
out.println("发送成功,可以用发送下一封信");
}
catch(Exception e){
out.println("发生错误:"+e.toString());
}
}
%>
<body>
</font><form action="mail.jsp" method="post">
<p class="STYLE3">发送人的地址:
<input name="from" type="text" />
*</p>
<p class="STYLE3"> 收信人的地址:
<input name="to" type="text" />
*</p>
<p class="style3">
<span class="STYLE3">选用发信服务器: </span>
<input type="text" name="server" value="smtp.163.com">
</p>
<p class="STYLE3">信件主题:
<input name="subject" type="text" />
</p>
<p class="STYLE1"><span class="STYLE3">信件内容:</span> <font size="+6" color="#FFFF33">
<textarea name="content" cols="70" rows="15"></textarea>
</font>
<font color="#FFFF33" size="+6">
<input type="submit" name="Submit" value="发送" />
<input type="reset" name="Submit2" value="重置" />
</form>
</body>
</html>