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

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

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

2020-07-27 21:55:24
字體:
供稿:網(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ā)表
主站蜘蛛池模板: 恩施市| 肥乡县| 济源市| 许昌县| 延长县| 惠东县| 鹤庆县| 修武县| 道孚县| 陕西省| 星座| 奈曼旗| 德州市| 绥棱县| 徐汇区| 泌阳县| 虹口区| 漳州市| 辽宁省| 永平县| 葫芦岛市| 泽普县| 荆州市| 建平县| 兰州市| 图们市| 东乡| 勃利县| 西乡县| 临夏县| 桓仁| 梁山县| 元氏县| 安义县| 尤溪县| 伊川县| 芜湖市| 娄底市| 启东市| 陆良县| 绥化市|