作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
Possible Duplicate:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25;
我试图通过 jsp 页面发送电子邮件,但它显示以下错误:
javax.mail.MessagingException
: Could not connect to SMTP host: www.gmail.com, port: 25, response: 421
这是我用来发送电子邮件的代码:
<%
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();
}
%>
谁能告诉我是什么导致了这个错误?
我是一名优秀的程序员,十分优秀!