我的邮件发送程序已经使用几年了,都没有问题,最近突然发生了问题。
javax.mail.SendFailedException。
但是我们的用户还是收到邮件了,不知道为什么既然有了发送失败的异常,为什么还能收到邮件呢,而且一直抛出这个异常。以前从来没有过。 Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", smtphost);
props.put("mail.store.protocol", "pop3");
props.put("mail.pop.host", pop3host);
session = Session.getDefaultInstance(props, null);从来都是这么用的,没有问题。
希望大家帮忙解决,谢谢了,很紧急。

解决方案 »

  1.   

    就楼主目前给出的代码来看,很难找出异常的真正原因。建议把
    session = Session.getDefaultInstance(props, null); 
    改为
    session = Session.getInstance(props, null); 
    试试看?从代码来看,你的SMTP服务器不需要验证?你自己的SMTP服务器吗?还是别人的允许匿名发送的SMTP服务器?提个建议,把SendFailedException的详细信息贴出来吧,绝对有助于问题的解决。呵呵。
      

  2.   

    楼上的兄台,这个程序运行比较久了,一直没有验证STMP,我想可能是因为这个是内部网络的内部服务器,所以不需要验证吧。
    这个是部分log[9/30/08 16:21:58:682 SGT] 0000002b SystemErr     R java.lang.Exception: SendFailed Exception. javax.mail.SendFailedException: Sending failed;
      nested exception is:
    class javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
      nested exception is:
    java.net.ConnectException: Connection refused: connect
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at xxx.utils.mail.Mailer.SendMessage(Mailer.java:114)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at xxx.servlet.feedback.FeedbackBean.sendFeedback(FeedbackBean.java:76)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at xxx.servlet.feedback.FeedbackServlet.DoProcess(FeedbackServlet.java:80)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at n1engine.com.servlet.n1_HttpServlet.service(n1_HttpServlet.java:100)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.servlet.SingleThreadModelServlet.service(SingleThreadModelServlet.java:127)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:972)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:907)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at ema.filter.ErrorDetectionFilter.trackRequestedURL(ErrorDetectionFilter.java:58)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at ema.filter.ErrorDetectionFilter.doFilter(ErrorDetectionFilter.java:45)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:696)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:641)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:475)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:92)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1425)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:92)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:193)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:725)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:847)
    [9/30/08 16:21:58:713 SGT] 0000002b SystemErr     R  at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1498)我很奇怪的是既然有这个异常,为什么用户还可以收到邮件呢?我换成我的邮件地址,就没有收到过
      

  3.   

    class javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; 从这句异常来看,你使用的SMTP服务器是localhost?这样的话,如果运行这个程序的那台机器(可能是你本机,也可能是Web服务器,看你写的程序的类型了)不是SMTP服务器,是不可能发得出去邮件的。我也纳闷了……这些异常信息是你在运行时看到的,还是检查日志时发现的?
    也许这些异常是其它程序所致,与你的程序无关?
    这一切,必须看实际情况才能得出结论,网友是很难帮得上忙了。自己再好好检查一下吧。