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

首頁 > 編程 > JSP > 正文

郵件發送簡單例子-jsp文件

2019-11-18 21:50:22
字體:
來源:轉載
供稿:網友
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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汉川市| 明光市| 宜城市| 育儿| 双鸭山市| 长寿区| 达日县| 颍上县| 四会市| 梨树县| 中山市| 甘孜县| 贺兰县| 扬中市| 蓝田县| 察隅县| 澄城县| 舞阳县| 二连浩特市| 兴山县| 凉山| 德州市| 元阳县| 东阳市| 宝鸡市| 赤城县| 临沭县| 德昌县| 新巴尔虎右旗| 安龙县| 正安县| 财经| 岫岩| 丰台区| 固镇县| 根河市| 饶平县| 枝江市| 驻马店市| 罗平县| 兴城市|