日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jsp中jsp中群发邮件群发邮件

發(fā)布時間:2025/5/22 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jsp中jsp中群发邮件群发邮件 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
jsp中群發(fā)郵件 1、獲取需要的jar文件,mail.jar([url]http://java.sun.com/products/javamail/[/url])和activation.jar([url]http://java.sun.com/products/javabeans/glasgow/jaf.html[/url]),將activation.jar和mail.jar復(fù)制到應(yīng)用程序的\WEB-INF\lib中,即可使用。 2、sendmail.jsp文件代碼:
<% @page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*,java.io.*,java.util.*,java.text.*, javax.mail.*, javax.mail.internet.*" %>
<jsp:useBean id="connBean" scope="session" class="opendb.opendb"/><html>
<head>
<title>JavaMail 電子郵件發(fā)送系統(tǒng)</title>
</head>
<body> <%
?String userName = (String)session.getAttribute("userName");
?String figure = (String)session.getAttribute("figure");
?String from = "";
?String to = "";
?ResultSet rs = null;
?String smtphost = "smtp.yeah.net"; // 發(fā)送郵件服務(wù)器
?String user = "zyf0808"; // 填寫自己的郵件服務(wù)器登錄用戶名
?String password = "123456789"; // 填寫你自己的郵件服務(wù)器登錄密碼
?String subject = connBean.change(request.getParameter("txtSubject")); // 郵件標(biāo)題
?String body =connBean.change(request.getParameter("txtContent"));// 郵件內(nèi)容
??? if(userName!=null && !userName.equals(""))
??{
?????ResultSet rst = connBean.ExecuteQuery("SELECT Email FROM Classmates WHERE UserName = '"+userName+"' ");
?????if (rst.next())
??????from = rst.getString("Email");????? //發(fā)件人地址
?????else from = "[email]zyf0808@yeah.net[/email]";? //換成可用的管理員的郵箱地址
??}
?else
??{
???//未登錄
%>
<SCRIPT language="JavaScript">
?? alert("對不起,您尚未登錄,只有登錄的管理員同學(xué)才能使用該功能!")
?? window.location.replace("../login.jsp");
</SCRIPT>
<%?
??}
?//得到除當(dāng)前登錄管理員外的所有用戶的郵箱
?rs = connBean.ExecuteQuery("SELECT Email FROM Classmates WHERE UserName <> '"+userName+"'");
??? while (rs.next())
?{
??to = rs.getString("Email"); // 接受人郵件地址
?? if (to !=null && !to.equals("") )
??{
??try
??{
???Properties props = new Properties();
???props.put("mail.smtp.host", smtphost);
???props.put("mail.smtp.auth","true");
???Session ssn = Session.getInstance(props, null); MimeMessage message = new MimeMessage(ssn); InternetAddress fromAddress = new InternetAddress(from);
???message.setFrom(fromAddress);
???InternetAddress toAddress = new InternetAddress(to);
???message.addRecipient(Message.RecipientType.TO, toAddress); message.setSubject(subject);
???message.setText(body); Transport transport = ssn.getTransport("smtp");
???transport.connect(smtphost, user, password);
???transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
???transport.close();
??}
??catch(Exception e)
???{
????out.println(e.toString());
???}
??}
?}
%>
<SCRIPT language="JavaScript">
?? alert("郵件已經(jīng)成功發(fā)送!")
?? window.location.replace("../index.jsp");
</SCRIPT>
</BODY>
</HTML>

總結(jié)

以上是生活随笔為你收集整理的jsp中jsp中群发邮件群发邮件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。