简体   繁体   English

无法发送邮件:无法将套接字转换为TLS。

[英]Unable to send mail: Could not convert socket to TLS;

The following code is working as Java application eclipse, But when it deployed in SAP PO server the below exception is thrown: 以下代码正在作为Java应用程序的日食运行,但是当将其部署在SAP PO服务器中时,将引发以下异常:

Note : Stand alone java file is running on my laptop(Windows) where as server is not Linux 注意:独立的java文件正在笔记本电脑(Windows)上运行,而服务器不是Linux

javax.mail.MessagingException: Could not convert socket to TLS; javax.mail.MessagingException:无法将套接字转换为TLS。 nested exception is: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl) 嵌套的异常是:java.net.SocketException:java.security.NoSuchAlgorithmException:构造实现时出错(算法:Default,提供者:SunJSSE,类:com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)

public static void main(String[] args) {
        PropertiesSerDto dto = new PropertiesSerDto();

        dto.setEmailAuth("true");
        dto.setEmailStarttlsEnable("true");
        dto.setEmailHost("outlook.office365.com");
        dto.setEmailPort("587");
        dto.setEmailPassword("1234");
        dto.setEmailFrom("test@mail.com");
        dto.setEmailUser("test@mail.com");
        String to="to@gmail.com";
        String subject="Mail Testing";
        String message = "Hello";
        try {
            sendHtmlEmail(dto,to,subject,message);
        } catch (AddressException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MessagingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void sendHtmlEmail(PropertiesSerDto dto, String to, String subject, String message) throws AddressException, MessagingException {

        // sets SMTP server properties
        Properties properties = new Properties();
        properties.put("mail.smtp.host", dto.getEmailHost());
        properties.put("mail.smtp.port", dto.getEmailPort());
        properties.put("mail.smtp.auth", dto.getEmailAuth());
        properties.put("mail.smtp.starttls.enable", dto.getEmailStarttlsEnable());
        final String user = dto.getEmailUser();
        final String password = dto.getEmailPassword();
        // creates a new session with an authenticator
        Authenticator auth = new Authenticator() {
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(user, password);
            }
        };
        Session session = Session.getInstance(properties, auth);
        // creates a new e-mail message
        Message messageContent = new MimeMessage(session);
        messageContent.setFrom(new InternetAddress(dto.getEmailFrom()));
        InternetAddress[] iAdressArray = InternetAddress.parse(to);
        messageContent.setRecipients(Message.RecipientType.TO, iAdressArray);
        messageContent.setSubject(subject);
        messageContent.setSentDate(new Date());
        // set plain text message
        messageContent.setContent(message, "text/html");
        // sends the e-mail
        Transport.send(messageContent);

    }

For the record to be left, I was having the same problem and thought it was an issue in the server configuration. 为了保留记录,我遇到了同样的问题,并认为这是服务器配置中的问题。 It turned out to be a firewall configuration. 原来是防火墙配置。 This was not letting out the connection requests to the smtp server. 这并未释放到smtp服务器的连接请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 SMTP 发送 email(获取 javax.mail.MessagingException:无法将套接字转换为 TLS;) - Unable to send an email using SMTP (Getting javax.mail.MessagingException: Could not convert socket to TLS;) 无法将套接字转换为Apache Commons Mail上的TLS - Could not convert socket to TLS on Apache Commons Mail javax.mail.MessagingException:无法在 JAVA 中将套接字转换为 TLS 异常 - javax.mail.MessagingException: Could not convert socket to TLS exception in JAVA 通过Java程序发送邮件(无法将套接字转换为TLS错误) - Sending Mail through Java program(Could not convert socket to TLS error) javax.mail.MessagingException:无法将套接字转换为TLS - javax.mail.MessagingException: Could not convert socket to TLS javax 无法将套接字转换为 TLS; - javax Could not convert socket to TLS; 通过 SMTP 发送邮件时出现“MessagingException:无法将套接字转换为 TLS” - Getting “MessagingException: Could not convert socket to TLS” when sending mail via SMTP 如何解决“邮件服务器连接失败; 嵌套的异常是javax.mail.MessagingException:无法将套接字转换为TLS;无法将套接字转换为TLS。 使用Spring-mvc? - How to fix “Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS; ” using Spring-mvc? Java 邮件逻辑:无法将套接字转换为 TLS - Java Mailing Logic: Could not convert socket to TLS Javamail 无法将套接字转换为 TLS GMail - Javamail Could not convert socket to TLS GMail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM