2001-03-23 09:40:00· wayne· yesky
源程序二:JavaMail 电子邮件发送系统的JSP实现程序代码: <%@ page import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*" %> <html> <head> <TITLE>JavaMail 电子邮件发送系统</TITLE> </HEAD> <BODY> <% try{ Properties props = new Properties(); Session sendMailSession; Store store; Transport transport; sendMailSession = Session.getInstance(props, null); props.put("mail.smtp.host", "smtp.abcd.com"); Message newMessage = new MimeMessage(sendMailSession); newMessage.setFrom(new InternetAddress(request.getParameter("from"))); newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(request.getParameter("to"))); newMessage.setSubject(request.getParameter("subject")); newMessage.setSentDate(new Date()); newMessage.setText(request.getParameter("text")); transport = sendMailSession.getTransport("smtp"); transport.send(newMessage); %> <p>你的邮件已发送,请返回。</p> <% } catch(MessagingException m) { out.println(m.toString()); } %> </BODY> </HTML>