写了个发邮件程序
public boolean send(){
        Collection<String> sendTo = new ArrayList<String>();
        sendTo.add(this.toAddress);
        String htmlMessage = content.buildContent();
        HtmlEmail email = new HtmlEmail();
        email.setHostName(this.smtpService);
        email.setSubject(this.subject);
        email.setCharset("GB2312");
        email.setAuthentication(userName,password);
        logger.info("toAddress="+toAddress);
        logger.info("htmlMessage="+htmlMessage);
        logger.info("smtpService="+smtpService);
        logger.info("subject="+subject);
        logger.info("userName="+userName);
        logger.info("password="+password);
        try {
            email.setFrom(fromAddress);
            for (String aTo : sendTo) {
                email.addTo(aTo);
            }
            email.setHtmlMsg(htmlMessage);
            email.send();
        }
        catch (EmailException ee) {
            ee.printStackTrace();
            return false;
        }
        return true;
    }
在main()中执行的话 邮件是能发到的,
但是我在应用程序中就不行了,报如下错误:
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.shaidc.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at com.sptd.ectm.ws.email.AbstractEmail.send(AbstractEmail.java:84)
at com.sptd.ectm.web.home.action.UserRegisterAction.doSubmit(UserRegisterAction.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 530 Authentication required at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1668)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1207)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:735)
at javax.mail.Transport.send(Transport.java:95)
at javax.mail.Transport.send(Transport.java:48)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 30 more
不知道大家碰到过没有