邮件发送简单例子-j文件_JSP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

邮件发送简单例子-j文件

作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0

本篇关键词:文件例子简单发送
黑客防线网安网讯:MailExample.jsp    <html>  <head>  <title>JSP JavaMail Example </title>  </head>    <body>    <%@ page import="java.util.*" %>  <%@ page import="javax.mail....
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>
  
  
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-16560-1.html
网站维护教程更新时间:2012-04-07 00:33:30  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer