通过smtps发送邮件时出错 [英] Error in sending mail through smtps

查看:564
本文介绍了通过smtps发送邮件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行下一行时,我连接到我的邮件服务器时收到以下异常

I am getting the below exception while connecting to my mailserver while executing the below line

transport.connect("test.mailserver.com",465,"test.user@test.com","testpwd");

异常是:

(javax.mail.MessagingException) javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: subject/issuer name chaining check failed

下面是代码:

protected static Session initializeSession(MailMessage p_msg) throws Exception{

    //Get the SMTP Host
    Properties prop = System.getProperties();
    prop.put( "mail.smtps.host", "test.mailserver.com" );
    prop.put("mail.transport.protocol", "smtps");
    prop.put("mail.smtps.auth", true);

    Session session = Session.getInstance(prop,null);
    session.setDebug( p_msg.getDebugMode() );
    return session;
}   
protected static void sendMessage(MimeMessage p_msg)  throws Exception{

    Properties prop = System.getProperties();

    Session session = Session.getDefaultInstance(prop, null);
    Transport transport = session.getTransport("smtps");
        transport.connect("test.mailserver.com",465,"test.user@test.com","testpwd");
    transport.sendMessage(p_msg, p_msg.getAllRecipients());
    transport.close();
}


推荐答案

像这样我自己原来,我通过以正确的顺序将证书放在服务器的证书链中,从而错误地配置了SSL。典型的Web浏览器中的SSL堆栈不关心这一点,但是(显然)Java中的客户端SSL引擎不能(或不会)处理以错误顺序呈现链接的服务器。

I dimly recall running into something like this myself. It turned out that I had configured SSL incorrectly by putting the certificates in the server's certificate chain in the wrong order. The SSL stacks in a typical web browser don't care about this, but (apparently) the client-side SSL engine in Java cannot (or will not) cope with a server that presents the chain in the wrong order.

所以,如果你没有运气与其他答案,请尝试查看您在邮件服务器上安装SSL证书等的方式。

So, if you get no luck with other answers, try looking at the way that you have installed the SSL certificate, etc on your mail server.

这篇关于通过smtps发送邮件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆