用带身份验证的smtp发送邮件失败。。请看代码。。。根据我从网上找的资料,应该对啊。
用带身份验证的smtp发送邮件失败。。请看代码。。。根据我从网上找的资料,应该对啊。
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import=" javax.mail.*, javax.mail.internet.*, javax.activation.*,java.util.*"%>
<html>
<head>
<TITLE>JSP meets JavaMail, what a sweet combo.</TITLE>
</HEAD>
<BODY>
<%
String username="netnice";
String password="781112";
try{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
sendMailSession = Session.getDefaultInstance(props, null);
sendMailSession.setDebug(true);
props.put("mail.smtp.host","smtp.163.com");
props.put("mail.smtp.auth","true"); //设置需要验证
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"));
newMessage.saveChanges(); //这个好象是必须的
transport = sendMailSession.getTransport("smtp");
transport.connect((String)props.get("mail.smtp.host"),username,password);//验证
transport.send(newMessage,newMessage.getAllRecipients());
transport.close();
%>
<P>Your mail has been sent.</P>
<%
}
catch(MessagingException m)
{
out.println(m.toString());
}
%>
</BODY>
</HTML>
以上代码不行啊。错误提示
javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.AuthenticationFailedException
///我用网络监视器观察实际发送的数据,
///发现验证过程是对的。服务器返回 235 .... seccess。。。
///这以后就发现程序并没有继续向服务器发送 数据了。这时应该就发生了验证错误了。
///下一步应该发送 MAIL FROM: 。。。。。这些才对啊。
// 为什么呢?难道是javamail的问题????
请教各位!!谢谢。