用带身份验证的smtp发送邮件失败。。请看代码。。。根据我从网上找的资料,应该对啊。

ChinaOk 2003-05-30 10:07:39
用带身份验证的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的问题????


请教各位!!谢谢。

...全文
451 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChinaOk 2003-05-30
  • 打赏
  • 举报
回复
谢谢。ok了。
leshui 2003-05-30
  • 打赏
  • 举报
回复
http://www.csdn.net/develop/Read_Article.asp?Id=14929

给你个例子参考一下
zez 2003-05-30
  • 打赏
  • 举报
回复
sendMessage() 试试
ChinaOk 2003-05-30
  • 打赏
  • 举报
回复
这是tomcat里显示的debug信息。

DEBUG: SMTPTransport trying to connect to host "smtp.163.com", port 25

DEBUG SMTP RCVD: 220 Welcome to coremail System(With Anti-Spam) 2.1 for www.163.
com

DEBUG: SMTPTransport connected to host "smtp.163.com", port: 25

DEBUG SMTP SENT: EHLO tech
DEBUG SMTP RCVD: 250-192.168.1.181
250-PIPELINING
250-SIZE 10240000
250-ETRN
250-AUTH=LOGIN PLAIN
250-AUTH LOGIN PLAIN
250 8BITMIME

DEBUG SMTP Found extension "PIPELINING", arg ""
DEBUG SMTP Found extension "SIZE", arg "10240000"
DEBUG SMTP Found extension "ETRN", arg ""
DEBUG SMTP Found extension "AUTH=LOGIN", arg "PLAIN"
DEBUG SMTP Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP Found extension "8BITMIME", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP SENT: AUTH LOGIN
DEBUG SMTP RCVD: 334 VXNlcm5hbWU6

DEBUG SMTP SENT: bmV0bmljZQ==
DEBUG SMTP RCVD: 334 UGFzc3dvcmQ6

DEBUG SMTP SENT: Mj23a7N0Ey
DEBUG SMTP RCVD: 235 Authentication successful

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s
mtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧