国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JSP > 正文

郵件發(fā)送簡(jiǎn)單例子-jsp文件

2024-09-05 00:20:48
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
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>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 华池县| 宝清县| 宁河县| 新疆| 丹阳市| 康定县| 鄯善县| 咸丰县| 荆州市| 泽库县| 岳普湖县| 广东省| 通榆县| 余姚市| 虞城县| 济南市| 三门峡市| 朝阳县| 驻马店市| 茌平县| 盱眙县| 喀喇| 思茅市| 加查县| 酒泉市| 陆丰市| 湖口县| 桂东县| 绥化市| 岑巩县| 云阳县| 寻乌县| 德令哈市| 濮阳县| 堆龙德庆县| 乳源| 荆州市| 綦江县| 曲靖市| 珲春市| 滨海县|