Java com.sun.mail.smtp.SMTPAddressFailedException:554 5.7.1 <cdae-jee-302-01.uci.cu[10.56.14.157]>:客户端主机被拒绝:访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/23485284/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <cdae-jee-302-01.uci.cu[10.56.14.157]>: Client host rejected: Access denied
提问by Yudiel
I'm trying to send a mail with JavaMail.
我正在尝试使用 JavaMail 发送邮件。
properties.put("mail.smtp.host", "smtp.estudiantes.ve");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.port",25);
properties.put("mail.smtp.mail.sender","[email protected]");
properties.put("mail.smtp.user", "[email protected]");
properties.put("mail.smtp.auth", "true");
session = Session.getDefaultInstance(properties);
session.setDebug(true);
System.setProperty("java.net.preferIPv4Stack", "true");
System.setProperty("javax.net.ssl.trustStore", "C:/Program Files/Java/jdk1.7.0_51/jre/lib/security/cacerts");
try{
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress((String)properties.get("mail.smtp.mail.sender")));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
    message.setSubject("Prueba");
    message.setText("Texto");
    Transport t = session.getTransport("smtp");
    t.connect((String)properties.get("mail.smtp.user"), "contrasenna");
    t.sendMessage(message, message.getAllRecipients());
    t.close();
}catch (MessagingException me){
    //Aqui se deberia o mostrar un mensaje de error o en lugar
    //de no hacer nada con la excepcion, lanzarla para que el modulo
    //superior la capture y avise al usuario con un popup, por ejemplo.
    return;
}
However, it throws the below exception:
但是,它会引发以下异常:
 javax.mail.SendFailedException: Invalid Addresses (com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <cdae-jee-302-01.uci.cu[10.56.14.157]>: Client host rejected: Access denied)
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1446)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:736)
    at uci.dalasqq.vista.AlarmasBean.sendEmail(AlarmasBean.java:116)
    at uci.dalasqq.vista.DashboardBean.updatepkicolors(DashboardBean.java:337)
    at uci.dalasqq.vista.DashboardBean.mainConfigPKI(DashboardBean.java:661)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <cdae-jee-302-01.uci.cu[10.56.14.157]>: Client host rejected: Access denied
    at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1344)
    ... 36 more
How is this caused and how can I solve it?
这是怎么引起的,我该如何解决?
回答by Adam Batkin
As far as I can tell, your code is working fine, but the mailserver you are using is rejecting your message with an error:
据我所知,您的代码运行良好,但您使用的邮件服务器拒绝您的邮件并显示错误:
554 5.7.1 <cdae-jee-302-01.uci.cu[10.56.14.157]>: Client host rejected: Access denied
Perhaps you need to log in to the server, or connect from a different host?
也许您需要登录到服务器,或从不同的主机连接?
回答by salyh
Try testing first from a simple command line client and look at the protocol trace
首先尝试从一个简单的命令行客户端进行测试并查看协议跟踪
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class Test {
    public static void main(String[] args) throws Exception{
        System.setProperty("java.net.preferIPv4Stack", "true");
        System.setProperty("javax.net.ssl.trustStore",
                "C:/Program Files/Java/jdk1.7.0_51/jre/lib/security/cacerts");
        Properties properties = new Properties();
        properties.put("mail.smtp.host", "smtp.estudiantes.ve");
        properties.put("mail.smtp.starttls.enable", "true");
        properties.put("mail.smtp.port", 25);
        properties.put("mail.smtp.mail.sender", "[email protected]");
        properties.put("mail.smtp.user", "[email protected]");
        properties.put("mail.smtp.auth", "true");
        Session session = Session.getInstance(properties); // do not use
                                                            // .getDefaultInstance
        session.setDebug(true);
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress((String) properties
                .get("mail.smtp.mail.sender")));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(
                "[email protected]"));
        message.setSubject("Prueba");
        message.setText("Texto");
        Transport t = session.getTransport("smtp");
        t.connect((String) properties.get("mail.smtp.user"), "contrasenna");
        message.saveChanges(); //do not forget this
        t.sendMessage(message, message.getAllRecipients());
        t.close();
    }
}
If its not working please post protocol trace and/or stacktrace
如果它不起作用,请发布协议跟踪和/或堆栈跟踪
回答by saikek
Also if you want to use SSL, add
另外,如果您想使用 SSL,请添加
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

