Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我尝试发送邮件时,为什么在握手过程中会出现远程主机关闭连接?_Java_Ssl_Weblogic_Jakarta Mail_Starttls - Fatal编程技术网

Java 当我尝试发送邮件时,为什么在握手过程中会出现远程主机关闭连接?

Java 当我尝试发送邮件时,为什么在握手过程中会出现远程主机关闭连接?,java,ssl,weblogic,jakarta-mail,starttls,Java,Ssl,Weblogic,Jakarta Mail,Starttls,我在WebLogic12c中运行了一个web应用程序,它可以发送邮件。 我得到了2个amazon实例,其中1个是第一个具有不同ip的实例的克隆。 因此,在原始实例中,我发送邮件没有问题,但在克隆实例中,我遇到了下一个异常: javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLHandshakeException: Remote host

我在WebLogic12c中运行了一个web应用程序,它可以发送邮件。 我得到了2个amazon实例,其中1个是第一个具有不同ip的实例的克隆。 因此,在原始实例中,我发送邮件没有问题,但在克隆实例中,我遇到了下一个异常:

javax.mail.MessagingException: Exception reading response;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: Remote host closed connection durin
g handshake
        at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java
:1462)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:37
0)
        at javax.mail.Service.connect(Service.java:288)
        at javax.mail.Service.connect(Service.java:169)
        at javax.mail.Service.connect(Service.java:189)
        at com.proximate.generales.service.impl.CorreoServiceImpl.sendMail(Corre
oServiceImpl.java:170)......
Caused by: java.io.EOFException: SSL peer shut down incorrectly
        at sun.security.ssl.InputRecord.read(InputRecord.java:482)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
        ... 96 more
以下是我发送邮件的代码:

public boolean sendMail() throws Exception {
    // try {
    final ResourceBundle props1 = ResourceBundle.getBundle(ConstantesGenerales.SMTP_BUNDLE);
    Properties props = new Properties();
    for (Enumeration e = props1.getKeys(); e.hasMoreElements();) {
        // Obtenemos el objeto
        Object obj = e.nextElement();
        props.put(obj, props1.getObject(obj.toString()));
    }

    Session session = Session.getInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(props1.getString("username"), props1.getString("password"));
        }
    });

    // Create a default MimeMessage object.

    SMTPMessage message = new SMTPMessage(session);
    MimeMultipart multiparte = new MimeMultipart("related");

    MimeBodyPart texto = new MimeBodyPart();
    texto.setText(mensaje.toString(), "US-ASCII", "html");
    multiparte.addBodyPart(texto);

    String rutaLogos = configuracionDAO.getRutaLogos();

    MimeBodyPart imagePart = new MimeBodyPart();

    imagePart.attachFile(new File(rutaLogos + ConstantesGenerales.LOGO_PUSHMATE));
    imagePart.setContentID(ConstantesGenerales.ETIQUETA_PUSHMATE);
    imagePart.setDisposition(MimeBodyPart.INLINE);
    multiparte.addBodyPart(imagePart);

    MimeBodyPart imagePart2 = new MimeBodyPart();
    imagePart2.attachFile(new File(rutaLogos + ConstantesGenerales.LOGO_PROXIMATE));
    imagePart2.setContentID(ConstantesGenerales.ETIQUETA_PROXIMATE);
    imagePart2.setDisposition(MimeBodyPart.INLINE);
    multiparte.addBodyPart(imagePart2);

    message.setContent(multiparte);
    message.setSubject(MimeUtility.encodeText(titulo, "utf-8", "B"));
    message.setSentDate(new Date());
    message.setFrom(new InternetAddress(props1.getString("username")));

    if (archivo != null) {
        BodyPart adjunto = new MimeBodyPart();
        adjunto.setFileName(archivo.getName());
        adjunto.setDataHandler(new DataHandler(new FileDataSource(archivo)));
        multiparte.addBodyPart(adjunto);
    }

    for (int i = 0; i < destinatarios.length; i++) {
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(destinatarios[i]));

    }

    // Send message
    // Transport.send(message);

    Transport t = session.getTransport("smtp");
    t.connect(props1.getString("username"), props1.getString("password"));
    t.sendMessage(message, message.getAllRecipients());
    t.close();
    // } catch (Exception e) {
    // e.printStackTrace();
    // //enviarCorreo();
    // }
    return true;
}
我还尝试使用以下属性:

username=services@host.com
password=Password
mail.host=smtpout.secureserver.net
mail.smtp.auth=true
mail.smtp.starttls.enable=false
mail.smtp.host=smtpout.secureserver.net
mail.smtp.port=465
mail.smtp.ssl.enable=true
mail.smtp.socketFactory.port=465
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.socketFactory.fallback=false
mail.transport.protocol=smtp
from=services@host.com
username=AKIAJK7XNV45BJ4YX7WQ
password=ArPec8p374QUSfHo80sAS4m5ShAgo/iOYlNQOv6/XTn+
mail.host=email-smtp.us-east-1.amazonaws.com
mail.smtp.auth=true
mail.smtp.port=587
mail.smtp.starttls.enable=true
mail.smtp.starttls.required=true
mail.transport.protocol=smtp
我甚至尝试放置属性,因此我不使用TLS或SSL,但在我的克隆实例中,我总是得到相同的异常,在我的原始实例中,邮件被发送。 有什么不对劲吗?
提前感谢。

清除套接字工厂属性并修复其他属性。这说明了什么?去掉套接字工厂属性并修复其他属性。表演什么?