MailExample.jspZaMLinux联盟 ZaMLinux联盟 <html>ZaMLinux联盟 <head>ZaMLinux联盟 <title>JSP JavaMail Example </title>ZaMLinux联盟 </head>ZaMLinux联盟 ZaMLinux联盟 <body>ZaMLinux联盟 ZaMLinux联盟 <%@ page import="java.util.*" %>ZaMLinux联盟 <%@ page import="javax.mail.*" %>ZaMLinux联盟 <%@ page import="javax.mail.internet.*" %>ZaMLinux联盟 <%@ page import="javax.activation.*" %>ZaMLinux联盟 ZaMLinux联盟 <%ZaMLinux联盟 String host = "yourmailhost";ZaMLinux联盟 String to = request.getParameter("to");ZaMLinux联盟 String from = request.getParameter("from");ZaMLinux联盟 String subject = request.getParameter("subject");ZaMLinux联盟 String messageText = request.getParameter("body");ZaMLinux联盟 boolean sessionDebug = false;ZaMLinux联盟 ZaMLinux联盟 // Create some properties and get the default Session.ZaMLinux联盟 Properties props = System.getProperties();ZaMLinux联盟 props.put("mail.host", host);ZaMLinux联盟 props.put("mail.transport.protocol", "smtp");ZaMLinux联盟 ZaMLinux联盟 Session mailSession = Session.getDefaultInstance(props, null);ZaMLinux联盟 ZaMLinux联盟 // Set debug on the Session so we can see what is going onZaMLinux联盟 // Passing false will not echo debug info, and passing trueZaMLinux联盟 // will.ZaMLinux联盟 mailSession.setDebug(sessionDebug);ZaMLinux联盟 ZaMLinux联盟 // Instantiate a new MimeMessage and fill it with theZaMLinux联盟 // required information.ZaMLinux联盟 Message msg = new MimeMessage(mailSession);ZaMLinux联盟 ZaMLinux联盟 msg.setFrom(new InternetAddress(from));ZaMLinux联盟 InternetAddress[] address = {new InternetAddress(to)};ZaMLinux联盟 msg.setRecipients(Message.RecipientType.TO, address);ZaMLinux联盟 msg.setSubject(subject);ZaMLinux联盟 msg.setSentDate(new Date());ZaMLinux联盟 msg.setText(messageText);ZaMLinux联盟 ZaMLinux联盟 // Hand the message to the default transport serviceZaMLinux联盟 // for delivery.ZaMLinux联盟 Transport.send(msg);ZaMLinux联盟 ZaMLinux联盟 out.println("Mail was sent to " + to);ZaMLinux联盟 out.println(" from " + from);ZaMLinux联盟 out.println(" using host " + host + ".");ZaMLinux联盟 ZaMLinux联盟 %>ZaMLinux联盟 </table>ZaMLinux联盟 </body>ZaMLinux联盟 </html>ZaMLinux联盟 ZaMLinux联盟