현재 구성은 3rabbitz 북이 구성된 서버에 postfix를 구성후 TLS(SSL) 구성 없이 relay를 허용하여 메일을 전달하는 형태로 구성이 되어 있습니다. 이와 같은 환경에서 아래와 같은 코드로 Java 메일 테스트를 수행하면 동일한 SSLException이 발생하는 것을 확인 했습니다.
import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendEmail { public static void main(String [] args) { // Recipient's email ID needs to be mentioned. String to = "to@company.com"; // Sender's email ID needs to be mentioned String from = "from@company.com"; // Assuming you are sending email from localhost String host = "12.34.56.78"; // Get system properties Properties properties = System.getProperties(); // Setup mail server properties.setProperty("mail.smtp.host", host); properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); // Get the default Session object. Session session = Session.getDefaultInstance(properties); session.setDebug(true); try { // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); // Set To: header field of the header. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set Subject: header field message.setSubject("This is the Subject Line!"); // Now set the actual message message.setText("This is actual message"); // Send message Transport.send(message); System.out.println("Sent message successfully...."); }catch (MessagingException mex) { mex.printStackTrace(); } } }
Exception Log:
DEBUG: setDebug: JavaMail version 1.4ea DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc] DEBUG SMTP: useEhlo true, useAuth false DEBUG SMTP: trying to connect to host "12.34.56.78", port 25, isSSL false DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? javax.mail.MessagingException: Exception reading response; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? 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:370) at javax.mail.Service.connect(Service.java:275) at javax.mail.Service.connect(Service.java:156) at javax.mail.Service.connect(Service.java:105) at javax.mail.Transport.send0(Transport.java:168) at javax.mail.Transport.send(Transport.java:98) at SendEmail.main(SendEmail.java:56) Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? at sun.security.ssl.InputRecord.handleUnknownRecord(InputRecord.java:710) at sun.security.ssl.InputRecord.read(InputRecord.java:527) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:928) at sun.security.ssl.AppInputStream.read(AppInputStream.java:105) at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97) at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) at java.io.BufferedInputStream.read(BufferedInputStream.java:265) at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75) at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440) ... 8 more
코드에서 properties.setProperty(“mail.smtp.socketFactory.class”, “javax.net.ssl.SSLSocketFactory”); 부분을 주석처리하면 메일이 정상적으로 발송되는데요. 3rabbitz 북 메일 설정이 이와 같은 형태로 구현이 된 것이라면 혹시 SSL을 이용하지 않도록 설정이 가능한지 확인 부탁 드리겠습니다.
참고로 Postfix에 TLS 구성을 해 보았는데 제가 정확하게 설정을 하지 못해서 그런 것인지 아니면 Java mail에서 SSL 이 TLS와는 관계가 없는 것인지 모르겠지만 메일 시스템에서는 250-STARTTLS 메시지가 찍히는대도 동일한 SSLException이 발생합니다.
현재 구현된 방식이 TLS만 지원하는 문제가 있습니다.
TLS가 아닌 방식의 메일도 지원하도록 하겠습니다.
개발이 완료되면 테스트 서버를 이용하여 테스트를 요청하도록 하겠습니다.
정확히 표현하자면 STARTTLS만을 지원하고 있습니다.
현재까지 확인한 바로는 SSL, TLS, STARTTLS 방식이 모두 다른 것 같습니다.
조금 더 확인하여 위의 모드들을 모두 적용 가능하도록 구현하도록 하겠습니다.
네, 확인 감사합니다~