当前位置: 代码迷 >> Java Web开发 >> [求助]发邮件的问题
  详细解决方案

[求助]发邮件的问题

热度:410   发布时间:2007-01-29 14:23:14.0
[求助]发邮件的问题

我发邮件时,系统总会提示:
发送邮件失败,原因可能是
Sending failed; nested exception is: class javax.mail.AuthenticationFailedException

请教一下,各位大侠:最好是附上改正的代码.谢谢.
源代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="../error/error.jsp" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import ="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>发送邮件</title>
</head>
<link rel="stylesheet" type="text/css" href="../image/com.css"/>
<%
request.setCharacterEncoding("gb2312");
InternetAddress[] address=null;
String mailserver="smtp.tom.com.";
String from=request.getParameter("jname");
String to=request.getParameter("sname");
String subject=request.getParameter("title");
String messageText=request.getParameter("message");

//boolean sessionDebug=false;
try{
//设定所要用的mail服务器和所使用的传输协议
java.util.Properties props=System.getProperties();
props.put("mail.smtp.host",mailserver);
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.auth", "true"); //这样才能通过验证

//产生Session服务
javax.mail.Session mailSession=javax.mail.Session.getDefaultInstance(props);
mailSession.setDebug(false);
Message msg=new MimeMessage(mailSession);
//设定发信人
msg.setFrom(new InternetAddress(from));
//设定收信人信箱
address=InternetAddress.parse(to,false);
msg.setRecipients(Message.RecipientType.TO,address);
//设定信中的主题
msg.setSubject(subject);
//没定送信人的时间
msg.setSentDate(new Date());
//设定传送信的MIME Type
msg.setText(messageText);

Transport.send(msg);
out.print("发送邮件成功");

}catch(Exception e){
out.print("发送邮件失败,原因可能是<ul>");
out.println(e.getMessage());
}
%>
</html>

搜索更多相关主题的帖子: import  邮件  源代码  page  

----------------解决方案--------------------------------------------------------
你的邮件服务器来源是?
你的学校的网? 还是宽带?
----------------解决方案--------------------------------------------------------

身份验证呢?


----------------解决方案--------------------------------------------------------
  相关解决方案