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

首頁 > 編程 > JSP > 正文

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

2020-06-01 23:18:36
字體:
來源:轉載
供稿:網友
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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大邑县| 安康市| 桃园县| 清远市| 南和县| 布拖县| 海城市| 双鸭山市| 开鲁县| 巴彦淖尔市| 八宿县| 华坪县| 嘉禾县| 沧源| 化州市| 法库县| 碌曲县| 长沙市| 新巴尔虎右旗| 银川市| 沽源县| 河西区| 灵寿县| 松滋市| 略阳县| 明溪县| 池州市| 拉萨市| 天长市| 连平县| 正蓝旗| 都兰县| 山丹县| 丰城市| 马公市| 百色市| 宁德市| 启东市| 靖江市| 永昌县| 都昌县|