编程技术 - 用JSP发送电子邮件
用JSP发送电子邮件
2004-04-23 15:18 pm来自:Linux文档
现载:Www.8s8s.coM
地址:无名
本文内容是html实例,在浏览器中显示为空,请查看源代码。
<!--
---------------------------begin sendmail.html------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<form name="form1" method="post" action="send.jsp">
<p>收信人:
<input type="text" name="to">
</p>
<p> 发信人:
<input type="text" name="from">
</p>
<p> 主题:
<input type="text" name="sub">
</p>
<p> 内容:
<textarea name="mess"></textarea>
</p>
<input type="submit" name="Submit" value="发送">
</form>
<p> </p>
</body>
</html>
-----------------------------end sendmail.html------------------------
---------------------------begin sendmail.jsp-------------------------
<%@page import="sun.net.smtp.SmtpClient,java.io.*"%>
<%
String from=String.valueOf(request.getParameter("from")).toString();
String to=String.valueOf(request.getParameter("to")).toString();
String sub=String.valueOf(request.getParameter("sub")).toString();
String mess=String.valueOf(request.getParameter("mess")).toString();
try{
SmtpClient client=new SmtpClient("linuxaid.com.cn");
client.from(from);
client.to(to);
PrintStream message=client.startMessage();
message.println("To:"+to);
message.println("Subject:"+sub);
message.println(mess);
client.closeServer();
out.println("邮件发送成功");
}
catch(Exception e){}
%>
-----------------------------end sendmail.jsp-------------------------
-->