脚本宝典收集整理的这篇文章主要介绍了邮件发送简单例子-jsp文件,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
M
ailEx
ample.jsp
<ht
ML>
<head>
<t
ITle>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("f
rom");
String s
ubject = request.getParameter("subject");
String messageText = request.getParameter("body");
boolean sessionDebug = false;
// Create some
PRo
PErties 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 w
hat 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
// requi
red 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>
脚本宝典总结
以上是脚本宝典为你收集整理的邮件发送简单例子-jsp文件全部内容,希望文章能够帮你解决邮件发送简单例子-jsp文件所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。