当前位置: 首页 > 图文教程 > 网络编程 > JSP > 邮件发送简单例子-jsp文件

JSP
Apache+Servlet+Jsp环境设置(中)
Apache+Servlet+Jsp环境设置(下)
基于EJB技术的商务预订系统的开发
让JSP页面过期, 保证每次JSP页面都是最新的.
JSP发送邮件实例
也谈用JSP实现新郎、sohu新闻系统的技术。
JSP抓取网页代码的程序
JSP应用的安全问题
将TOMCAT装入IIS全攻略
通过JDBC连接oracle数据库的十大技巧
JSP安全性初探
JSP漏洞大观
关于JSP中文问题的解决方法
JSP/JAVABEAN+TOMCAT4.0.5+MYSQL组合建站总结
WIN2000+PHP+MYSQL+TOMCAT+JSP完全整合安装手册
jsp连接数据库大全
用JSP下载word文件(不会直接用IE打开)
几则JSP入门知识总结
JSP迅速入门
Jsp如何实现网页的重定向

JSP 中的 邮件发送简单例子-jsp文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 51 ::
收藏到网摘: n/a

MailExample.jsp
<html>
<head>
<title>JSP JavaMail Example </title>
</head>
<body>
<%@ page import="java.util.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<%
String host = "yourmailhost";
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");
String messageText = request.getParameter("body");
boolean sessionDebug = false;
// Create some properties and get the default Session.
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
// Set debug on the Session so we can see what is going on
// Passing false will not echo debug info, and passing true
// will.
mailSession.setDebug(sessionDebug);
// Instantiate a new MimeMessage and fill it with the
// required information.
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
// Hand the message to the default transport service
// for delivery.
Transport.send(msg);
out.println("Mail was sent to " + to);
out.println(" from " + from);
out.println(" using host " + host + ".");
%>
</table>
</body>
</html>