使用commons-mail组合实现发送附件,但总是发送不成功

李渊 发布于 2011/03/26 07:56
阅读 1K+
收藏 1

小弟最近在写一个简易的方便发附件的小玩具。

界面如下:

现在遇到的问题就是发送代码在main控制台运行是可以的。可是搬到GUI处理就有问题。用户名什么的都输入正确。

我网上找了,可能是smtp服务商那边有问题:需要验证码……下面是错误提示:(我几次单步跟了进去,没发现哪里有空值,还有最下面提示Caused by: javax.mail.AuthenticationFailedException,这个就可能是服务商那边的问题了)

2011-3-26 7:51:27 cc.apl.mail.MyEmailSender send
严重: null
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.qq.com:25
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
        at org.apache.commons.mail.Email.send(Email.java:1267)
        at cc.apl.mail.MyEmailSender.send(MyEmailSender.java:39)
        at cc.apl330.view.MainFrame.jButton3ActionPerformed(MainFrame.java:332)
        at cc.apl330.view.MainFrame.access$200(MainFrame.java:31)
        at cc.apl330.view.MainFrame$3.actionPerformed(MainFrame.java:135)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6041)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
        at java.awt.Component.processEvent(Component.java:5806)
        at java.awt.Container.processEvent(Container.java:2058)
        at java.awt.Component.dispatchEventImpl(Component.java:4413)
        at java.awt.Container.dispatchEventImpl(Container.java:2116)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
        at java.awt.Container.dispatchEventImpl(Container.java:2102)
        at java.awt.Window.dispatchEventImpl(Window.java:2440)
        at java.awt.Component.dispatchEvent(Component.java:4243)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Caused by: javax.mail.AuthenticationFailedException
        at javax.mail.Service.connect(Service.java:306)
        at javax.mail.Service.connect(Service.java:156)
        at javax.mail.Service.connect(Service.java:105)
        at javax.mail.Transport.send0(Transport.java:168)
        at javax.mail.Transport.send(Transport.java:98)
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
        ... 30 more

 

 

 

加载中
0
巴叔
巴叔

AuthenticationFailedException异常是用户名和密码验证的错误。

ps:现在很多邮件服务提供商都做了限制,比如:163就不能用客户端软件访问邮箱的,只能通过web访问。

你还是仔细看看你登录的smtp.qq.com服务器是否允许客户端使用吧。

0
李渊
李渊

smtp.qq.com服务器允许客户端使用的。

我在命令行下可以发邮件

返回顶部
顶部