One Star

[resolved] MessagingException caused by SSLException in tSendMail

Hello, I'm facing following weird error.
Platform: Talend Open Studio 4.2.3
I create a simple job with a tSendMail component with minimal settings, no SSL, no STARTTLS.
I export it as an autonomous job and run it on Ubuntu server. It works.
Then I export it as a web service (WAR) and deploy it on the same Ubuntu server on Tomcat 6. In this case I get:
Exception in component tSendMail_1
javax.mail.MessagingException: Could not connect to SMTP host: xxx.xxx.xxx.xxx, port: 25;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at opvdominocad.testsendmail_0_1.TestSendMail.tSendMail_1Process(TestSendMail.java:364)
at opvdominocad.testsendmail_0_1.TestSendMail.runJobInTOS(TestSendMail.java:549)
at opvdominocad.testsendmail_0_1.TestSendMail.runJob(TestSendMail.java:448)
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.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.QSMethodHandler.invokeEndpointFromGet(QSMethodHandler.java:129)
at org.apache.axis.transport.http.QSMethodHandler.invoke(QSMethodHandler.java:94)
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.axis.transport.http.AxisServlet.processQuery(AxisServlet.java:1226)
at org.apache.axis.transport.http.AxisServlet.doGet(AxisServlet.java:249)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1096)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1107)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
... 44 more

Maybe is something connected with Tomcat or with the web services? Note that if I run the same job on Tomcat on another machine (but also with a different SMTP host) it works...
I'm going mad. Any help will be greatly appreciated!
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] MessagingException caused by SSLException in tSendMail

Thanks for the reply.
I checked and unchecked the option STARTTLS, but no difference in the result.
Finally I solved the problem with a tJava, which sends the email.
Its imports (needs 2 tLibraryLoad for mail.jar and activation.jar):
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

Its code:
//build and send the email
Properties props = new Properties();
props.put("mail.smtp.host", context.SMTP_HOST);
Session mail_session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mail_session);
msg.setFrom(new InternetAddress(context.MAIL_FROM));
Vector<String> recipients = new Vector<String>();
recipients.addElement((String)globalMap.get("mailcom"));
recipients.addElement((String)globalMap.get("mailcli"));
InternetAddress[] addressTo = new InternetAddress;
for (int i = 0; i < recipients.size(); i++)
addressTo = new InternetAddress((String)recipients.elementAt(i));
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(context.MAIL_SUBJECT);
msg.setSentDate(new Date());
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(context.MAIL_TEXT, "text/html");
mp.addBodyPart(mbp);
//add attachments
File attachments_folder = new File(context.ATTACHMENTS_SOURCE_FOLDER);
if (attachments_folder!=null){ //attachments folder exist
File[] files = attachments_folder.listFiles();
if (files!=null){
for(File file : files){
if (file.isFile()){
mbp = new MimeBodyPart();
DataSource source = new FileDataSource(file);
mbp.setDataHandler(new DataHandler(source));
mbp.setFileName(file.getName());
mp.addBodyPart(mbp); //add bodypart to the multipart
}
}
}
}
msg.setContent(mp);
Transport.send(msg);
2 REPLIES
Community Manager

Re: [resolved] MessagingException caused by SSLException in tSendMail

Hi
Try to check the option STARTTLS and test again.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] MessagingException caused by SSLException in tSendMail

Thanks for the reply.
I checked and unchecked the option STARTTLS, but no difference in the result.
Finally I solved the problem with a tJava, which sends the email.
Its imports (needs 2 tLibraryLoad for mail.jar and activation.jar):
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

Its code:
//build and send the email
Properties props = new Properties();
props.put("mail.smtp.host", context.SMTP_HOST);
Session mail_session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(mail_session);
msg.setFrom(new InternetAddress(context.MAIL_FROM));
Vector<String> recipients = new Vector<String>();
recipients.addElement((String)globalMap.get("mailcom"));
recipients.addElement((String)globalMap.get("mailcli"));
InternetAddress[] addressTo = new InternetAddress;
for (int i = 0; i < recipients.size(); i++)
addressTo = new InternetAddress((String)recipients.elementAt(i));
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(context.MAIL_SUBJECT);
msg.setSentDate(new Date());
Multipart mp = new MimeMultipart();
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(context.MAIL_TEXT, "text/html");
mp.addBodyPart(mbp);
//add attachments
File attachments_folder = new File(context.ATTACHMENTS_SOURCE_FOLDER);
if (attachments_folder!=null){ //attachments folder exist
File[] files = attachments_folder.listFiles();
if (files!=null){
for(File file : files){
if (file.isFile()){
mbp = new MimeBodyPart();
DataSource source = new FileDataSource(file);
mbp.setDataHandler(new DataHandler(source));
mbp.setFileName(file.getName());
mp.addBodyPart(mbp); //add bodypart to the multipart
}
}
}
}
msg.setContent(mp);
Transport.send(msg);