email组件问题,请指教

mwyking 2009-05-20 11:59:41
换成JDK1。6就可以了,但又出现新问题。
在运行时出错,希望大虾们指教
错误提示如下:




org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.tom.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1138)
at org.apache.commons.mail.Email.send(Email.java:1163)
at com.v512.SendMailServlet.doPost(SendMailServlet.java:32)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:319)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1128)
... 18 more





程序代码如下:

sendMailServlet.java文件

package com.v512;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class SendMailServlet extends HttpServlet {

private static final long serialVersionUID = -9201649826567946642L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);

}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
SimpleEmail email = new SimpleEmail();
email.setHostName("smtp.sina.com");
email.setAuthentication("web08", "web2008");
email.setCharset("UTF-8");
try {
email.setFrom(request.getParameter("from"));
email.addTo(request.getParameter("to"));
email.setSubject(request.getParameter("subject"));
email.setMsg(request.getParameter("content"));
email.send();
request.setAttribute("sendmail.message", "邮件发送成功!");
} catch (EmailException e) {
e.printStackTrace();
request.setAttribute("sendmail.message", "邮件发送不成功!");
}
request.getRequestDispatcher("/sendResult.jsp").forward(request,
response);
}

}


<%@ page pageEncoding="UTF-8" %>
<!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=utf-8" />
<title>无标题文档 </title>
</head>


sendMeil.jsp 文件


<body>
<p align="center">发送邮件的程序 </p>
<form id="form1" name="form1" method="post" action=" <%=request.getContextPath()%>/servlet/sendMail">
<table width="516" height="253" border="0" align="center">
<tr>
<td>收件人: </td>
<td> <label>
<input type="text" name="to" id="to" />
</label> </td>
</tr>
<tr>
<td>发件人: </td>
<td> <label>
<input type="text" name="from" id="from" />
</label> </td>
</tr>
<tr>
<td>主题: </td>
<td> <label>
<input type="text" name="subject" id="subject" />
</label> </td>
</tr>
<tr>
<td>内容: </td>
<td> <label>
<textarea name="content" id="content" cols="45" rows="8"> </textarea>
</label> </td>
</tr>
<tr>
<td> <label>
<input type="submit" name="button" id="button" value="提交" />
</label> </td>
<td> <label>
<input type="reset" name="button2" id="button2" value="重置" />
</label> </td>
</tr>
</table>
</form>
<p align="center">  </p>
<p>  </p>
</body>

</html>


sendResult.jsp文件

<%@ page language="java" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>display upload result </title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<center>
<p> ${requestScope['sendmail.message'] } </p>
</center>
</body>
</html>



...全文
83 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mwyking 2009-05-20
  • 打赏
  • 举报
回复
tom,sina,163,126.com都试过了,都是不行。

错误提示这个是哪出错?
Caused by: javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:319)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1128)
... 18 more
marcblue 2009-05-20
  • 打赏
  • 举报
回复
试试别的邮箱看看
Delphi 6是一个功能强大且高效的快速应用程序开发工具,它可协助您快速且容易地开发各种新一代的电子商务应用系统。Delphi的BizSnap运用Web Service技术轻松地整合企业与企业(B2B Business to Business)之间的信息交换。MSnap则运用新式软件组件的技术简化网反应用程序的开发复杂度。Datasnap则是整合各种数据访问的技术以简化多层分布式数据库应用系统的构建。从Delphi1.0到Delphi6.0,Borland公司在每一个版本皆尽了最大的努力来加强Delphi的功能。正因为如此,所以软件工程师可以轻松地使用Delphi撰写各式各样的应用程序,无论是文件管理、Client/Server或Multi-Tier数据库应用程序、因特网应用程序,甚或是企业间的跨平台的应用程序皆难不倒它。 面对 Delphi 6这么完整的功能,如何决定本书的章节内容,真是难倒作者。经过几番思索及综合多位读者的意见后,最后决定了本书所显示的内容。至于不足的部分作者会以专门的书籍来讨论数据库及其他高级的内容。本书的重点将着重于基础Object Pascal程序撰写的技巧、Delphi程序结构的彻底认识、各种VCL组件的应用、各种文件类型的高级处理、各种不同的数据库应用程序、Client/Server数据库应用程序及其他Object Pascal提高部分的应用,例如:多线程的程序撰写与Delphi VCL组件的制作。除此之外,作者另外以四个附录章节来讨论 Object Pascal与Delphi所提供的各种内置函数,希望通过Object Pascal的认识与Delphi内置函数的应用可以提高您程序开发的效率。 本书由第三波资讯股份有限公司提供版权,经中国铁道出版社计算机图书项目中心审选,王占清、李之明、李自运、崔仙翠、敖省林、陈兰芳等同志完成了本书的整稿及编排工作。 最后,希望本书可以协助您打开面向对象程序设计的大门,如果您讨本书有任何的批评与指教,欢迎E-mail至carosl@ms22.hinet.net。

62,635

社区成员

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

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