国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 平顺县| 泌阳县| 成都市| 万全县| 惠东县| 普陀区| 吴忠市| 綦江县| 芦山县| 河南省| 通化县| 大石桥市| 会泽县| 莱州市| 崇左市| 维西| 北京市| 左权县| 朝阳区| 洪泽县| 巴林右旗| 鄂伦春自治旗| 格尔木市| 贺州市| 甘南县| 西乌珠穆沁旗| 郴州市| 荃湾区| 桂平市| 连南| 应城市| 华坪县| 黄龙县| 龙海市| 老河口市| 托克托县| 军事| 夏津县| 剑河县| 通城县| 县级市|