1
Possible Duplicate:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25;javax.mail.MessagingException的:無法連接到SMTP主機
我試圖通過JSP頁面發送一封電子郵件,但它顯示了以下錯誤:
javax.mail.MessagingException
: Could not connect to SMTP host: www.gmail.com, port: 25, response: 421
這是我的代碼m用於發送電子郵件:
<%
try
{
String host = "www.gmail.com";
String to = request.getParameter("to");
String from = request.getParameter("from");
String subject = request.getParameter("subject");
String messageText = request.getParameter("body");
boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
mailSession.setDebug(sessionDebug);
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);
Transport.send(msg);
out.println("Mail was sent to " + to);
out.println(" from " + from);
out.println(" using host " + host + ".");
}
catch (MessagingException mex)
{
System.out.println("Error: unable to send message....");
mex.printStackTrace();
}
%>
有人能告訴我是什麼原因導致了這個錯誤?
[報價IETF - RFC 2821(HTTP:// datatracker。 ietf.org/doc/rfc2821/):'421:服務不可用,關閉傳輸通道 –
Jasper