简体   繁体   中英

com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <cdae-jee-302-01.uci.cu[10.56.14.157]>: Client host rejected: Access denied

I'm trying to send a mail with 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","miemail@estudiantes.ve");
properties.put("mail.smtp.user", "miemail@estudiantes.ve");
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("amigo@estudiantes.ve"));
    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?

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?

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", "miemail@estudiantes.ve");
        properties.put("mail.smtp.user", "miemail@estudiantes.ve");
        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(
                "amigo@estudiantes.ve"));
        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

另外,如果要使用SSL,请添加

properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM