안녕하세요,
메일 시스템 변경으로 smtp로 메일 전송 테스트를 하고 있는 데 계속 오류가 나네요...
방화벽 문제인지 알았는 데 방화벽 막혀 있는 게 없다고 해서 혹시나 아실 까 올려봅니다.
String fromMail = request.getParameter("mailFrom");
String toMail = request.getParameter("mailTo");
// 메일 인코딩
final String bodyEncoding = "UTF-8"; //콘텐츠 인코딩
String subject = "메일 발송 테스트";
String fromEmail = fromMail;
String fromUsername = "SYSTEM MANAGER";
String toEmail = toMail; // 콤마(,)로 여러개 나열
final String username = name;
final String password = password;
final String host = host;
// 메일 옵션 설정
Properties props = new Properties();
//2021.03.31 test
//props.put("mail.smtp.user", toMail);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.host", host);
//props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.trust", host);
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.ssl.protocols", "SSLv2Hello SSLv3"); // 이 부분이 중요!!
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.debug", "true");
//props.put("mail.smtp.socketFactory.fallback", "false");
Authenticator auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
};
Session session = Session.getInstance(props, auth);
try {
MimeMessage message = new MimeMessage(session);
message.addHeader("content-type", "text/HTML charset=UTF-8");
message.addHeader("format", "flowed");
message.addHeader("content-Transfer-Encoding", "8bit");
message.setFrom(new InternetAddress(fromMail, "test"));
message.setSubject("메일 전송 테스트", "UTF-8");
message.setText("메일 전송 테스트 내용", "UTF-8");
message.setSentDate(new Date());
message.setRecipient(Message.RecipientType.TO, new InternetAddress(toMail));
Transport.send(message);
} catch ( Exception e ) {
e.printStackTrace();
}
이렇게 발송을 해보면, 이런 에러가 나는 데
ssl enable 옵션을 줬는 데 왜 로그에는 isSSL false 이렇게 찍히는 지 모르겠네요...
DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: /usr/java/jdk1.6.0_38/jre/lib/javamail.providers (No such file or directory)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: /usr/java/jdk1.6.0_38/jre/lib/javamail.address.map (No such file or directory)
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.xxxx.com", port 465, isSSL false
DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Received fatal alert: unexpected_message
javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: Received fatal alert: unexpected_message
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:297)
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 trip.view.action.TripAction.MailSend3(TripAction.java:2530)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
at jeus.servlet.engine.ServletWrapper.executeServlet(ServletWrapper.java:242)
at jeus.servlet.filter.FilterChainImpl.internalDoFilter(FilterChainImpl.java:141)
at jeus.servlet.filter.FilterChainImpl.doFilter(FilterChainImpl.java:93)
at filter.LoginCheckFilter.doFilter(LoginCheckFilter.java:75)
at jeus.servlet.filter.FilterChainImpl.internalDoFilter(FilterChainImpl.java:124)
at jeus.servlet.filter.FilterChainImpl.doFilter(FilterChainImpl.java:93)
at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:204)
at jeus.servlet.engine.WebtobRequestProcessor.run(WebtobRequestProcessor.java:217)
Caused by: javax.net.ssl.SSLException: Received fatal alert: unexpected_message
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1837)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1019)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1203)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:818)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
하다가 너무 안되서, 옵션을 이렇게 주면 isSSL true 인데도 역시 오류가 납니다.
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.starttls.enable", "true");
props.put("mail.smtps.socketFactory.port", "465");
props.put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtps.port", "465");
props.put("mail.smtps.host", "smtp.xxxx.com");
props.put("mail.smtps.auth", "true");
props.put("mail.smtp.user", username);
props.put("password", password);
props.put("mail.debug", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.smtps.debug", "true");
// props.put("mail.imap.host", "smtp.xxxx.com");
//props.put("mail.imap.auth", "true");
props.put("mail.imap.Enable", "true");
//props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtps.ssl.enable", "true");
props.put("mail.smtps.ssl.trust", "smtp.xxxx.com");
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: /usr/java/jdk1.6.0_38/jre/lib/javamail.address.map (No such file or directory)
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.xxxx.com", port 465, isSSL true
DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Received fatal alert: unexpected_message
javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: Received fatal alert: unexpected_message
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 trip.view.action.TripAction.MailSend4(TripAction.java:2658)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:818)
at jeus.servlet.engine.ServletWrapper.executeServlet(ServletWrapper.java:242)
at jeus.servlet.filter.FilterChainImpl.internalDoFilter(FilterChainImpl.java:141)
at jeus.servlet.filter.FilterChainImpl.doFilter(FilterChainImpl.java:93)
at filter.LoginCheckFilter.doFilter(LoginCheckFilter.java:75)
at jeus.servlet.filter.FilterChainImpl.internalDoFilter(FilterChainImpl.java:124)
at jeus.servlet.filter.FilterChainImpl.doFilter(FilterChainImpl.java:93)
at jeus.servlet.engine.ServletWrapper.execute(ServletWrapper.java:204)
at jeus.servlet.engine.WebtobRequestProcessor.run(WebtobRequestProcessor.java:217)
Caused by: javax.net.ssl.SSLException: Received fatal alert: unexpected_message
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:190)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1837)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1019)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1203)