<%@ page contentType= "text/html; charset=gb2312 " language= "java " errorPage= "../error/error.jsp " %>
<%@ page import= "java.util.* " %>
<%@ page import = "javax.mail.* " %>
<%@ page import= "javax.mail.internet.* " %>
<%@ page import= "javax.activation.* " %>
<html>
<head>
<title> JavaMail Example </title>
</head>
<body>
<%
try
{
Properties props = new Properties();
Session sendMailSession;
Transport transport;
sendMailSession = Session.getInstance(props,null);
props.put( "mail.smtp.host ", "localhost ");
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> Your mail has been sent. </p>
<%
}catch(MessagingException m)
{
out.println(m.toString());
}
%>
</body>
</html>
--------------------------
运行得下面的异常:
javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25, response: -1
------解决方案--------------------
本机的smtp服务器安装配置了没有?
端口25有没有被其他程序占用?