使用JavaMail发邮件问题

一、邮件发不成功出错javax.mail.SendFailedException: Sending failed
告警邮件通知日志中报错,请帮忙分析是什么问题?
详细信息如下:
2012/07/05 14:38:53 ERROR MailNotifyEntry  mail error!
javax.mail.SendFailedException: Sending failed;
  nested exception is:
        class javax.mail.MessagingException: 550 Invalid User
        at javax.mail.Transport.send0(Transport.java:218)
        at javax.mail.Transport.send(Transport.java:80)
        at com.fault.notify.MailNotifyEntry.sendMail(MailNotifyEntry.java:476)
        at com.fault.notify.MailNotifyEntry.doNotify(MailNotifyEntry.java:262)
        at com.fault.notify.MailNotifyServer$ContextProcessor.run(MailNotifyServer.java:158)
 
或者:
javax.mail.SendFailedException: Sending failed; nested exception is:
     class javax.mail.MessagingException: 555 syntax error (eyou mta) 
     at javax.mail.Transport.send0(Transport.java:218) 
     at javax.mail.Transport.send(Transport.java:80) 
     at com.fault.notify.MailNotifyEntry$OneMailProcessRunnable.run(MailNotifyEntry.java:467) 
     at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743) 
     at java.lang.Thread.run(Thread.java:637)
 
结论:
  配置邮件通知规则的输出设置参数时,mail.from的值没有填写,或者填写不对,不是正确的邮件服务的用户名。
   
  
  
  
  二、邮件发送AuthenticationFailedException错误
  在用JavaMail发邮件时,如果邮件发送不成功有如下日志输出:

012/06/11 11:24:03 ERROR MailNotifyEntry  mail error!
javax.mail.SendFailedException: Sending failed;
  nested exception is:
        class javax.mail.AuthenticationFailedException
        at javax.mail.Transport.send0(Transport.java:218)
        at javax.mail.Transport.send(Transport.java:80)
        at com.fault.notify.MailNotifyEntry.sendMail(MailNotifyEntry.java:476)
        at com.fault.notify.MailNotifyEntry.doNotify(MailNotifyEntry.java:262)
        at com.fault.notify.MailNotifyServer$ContextProcessor.run(MailNotifyServer.java:158)

出错日志提示:class javax.mail.AuthenticationFailedException

查询JavaMail资料,这个异常的解释是“This exception is thrown when the connect method on a Store or Transport object fails due to an authentication failure (e.g., bad user name or password)”

所以需要检查登录邮件服务器的用户名、密码是否正确。

另外,发送邮件时默认使用的邮件服务端口号是25,如果不是使用默认端口25,可通过mail.smtp.port参数设置上参数值。

默认是25,如果邮件服务不是25,给定了其它端口号,要在NMS的邮件通知规则的通知设置中添加上,例如 参数名mail.smtp.port,参数值123


参考 http://www.websina.com/bugzero/kb/sunmail-properties.html

mail.smtp.port:The SMTP server port to connect to, if the connect() method doesn't explicitly specify one. Defaults to 25.

 
另外,要保证与邮件服器的110,25端口是通的,可在发送邮件的服务器上telnet 邮件服务器的这两个端口验证下,保证端口要通。

关于邮件服务端口的参考如下:

    25端口(SMTP):25端口为SMTP(Simple Mail Transfer Protocol,简单邮件传输协议)服务所开放的,是用于发送邮件。如今绝大多数邮件服务器都使用该协议。当你给别人发送邮件时,你的机器的某个动态端口(大于1024)就会与邮件服务器的25号端口建立一个连接,你发送的邮件就会通过这个连接传送到邮件服务器上,保存起来。

  109端口(POP2):109端口是为POP2(Post Office Protocol Version 2,邮局协议2)服务开放的,是用于接收邮件的。

  110端口(POP3):110端口是为POP3(Post Office Protocol Version 3,邮局协议3)服务开放的,是用于接收邮件的。

  143端口(IMAP):143端口是为IMAP(INTERNET MESSAGE ACCESS PROTOCOL)服务开放的,是用于接收邮件的。

猜你喜欢

转载自blog.csdn.net/zhigang0529/article/details/83176815
今日推荐