首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port:

2014-01-26 
%@ page contentType text/html charsetgb2312 language java errorPage ../error/error.jsp

<%@ 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有没有被其他程序占用?

        

热点排行