tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tamás Greguss (JIRA) <j...@apache.org>
Subject [jira] [Comment Edited] (TOMEE-1697) javamail: sending email fails
Date Sat, 23 Jan 2016 09:48:39 GMT

    [ https://issues.apache.org/jira/browse/TOMEE-1697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15113670#comment-15113670
] 

Tamás Greguss edited comment on TOMEE-1697 at 1/23/16 9:48 AM:
---------------------------------------------------------------

Ok, I have found an almost completely different way how to use JavaMail API to send e-mail
on SSL connection and it works well with new version of TomEE. However this new code does
not work with TomEE 1.7.1. So is there an undocumented change in the java mail API?

Another problem is that for sending html emails I use HtmlEmail class from Apache Commons
Email library that underneath uses Java Mail API. And it also fails sending email on TomEE
1.7.3. So I don't think that the changes in the geronimo java mail library are correct changes.

Or backward incompatibility is intentional? In this case why isn't it well documented?

Here is the code that uses HtmlEmail class:

{noformat}
public static void SendMailSSL( String to_address, String to_name, String from_address, String
from_name, String subject, String message, String smtpHost, int smtpPort, String senderuser,
String senderpass ) throws RuntimeException {
		try {
			HtmlEmail email = new HtmlEmail();
			email.setHostName(smtpHost);
			email.setSmtpPort(smtpPort);
			email.setAuthentication(senderuser, senderpass);
			email.setSSLOnConnect(true);
			email.setFrom(from_address, from_name);
			email.addTo(to_address, to_name);
			email.setSubject(subject);
			email.setContent(message, EmailConstants.TEXT_HTML);
			email.setCharset(EmailConstants.UTF_8);

			email.send();
		} catch (EmailException ex) {
			throw new RuntimeException("Sending email failed: " + ex.getMessage() + " ### " + ex.toString()
					+ " ### " + to_address + " " + to_name + " " + from_address + " " + from_name + " " +
subject + " " + message + " " + senderuser + " " + senderpass);
		}
	}
{noformat}

This is very simple code and I cannot change anything in it to work on new TomEE 1.7.3. So
I think the java mail library that is included in TomEE 1.7.3 is not correct.


was (Author: gregtom):
Ok, I have found an almost completely different way how to use JavaMail API to send e-mail
on SSL connection and it works well with new version of TomEE. However this new code does
not work with TomEE 1.7.1. So is there an undocumented change in the java mail API?

Another problem is that for sending html emails I use HtmlEmail class from Apache Commons
Email library that underneath uses Java Mail API. And it also fails sending email on TomEE
1.7.3. So I don't think that the changes in the geronimo java mail library are correct changes.

Or backward incompatibility is intentional? In this case why isn't it well documented?

Here is the code that uses HtmlEmail class:

{noformat}
public static void SendMailSSL( String to_address, String to_name, String from_address, String
from_name, String subject, String message, String smtpHost, int smtpPort, String senderuser,
String senderpass ) throws RuntimeException {
		try {
			HtmlEmail email = new HtmlEmail();
			email.setHostName(smtpHost);
			email.setSmtpPort(smtpPort);
			email.setAuthentication(senderuser, senderpass);
			email.setSSLOnConnect(true);
			email.setFrom(from_address, from_name);
			email.addTo(to_address, to_name);
			email.setSubject(subject);
			email.setContent(message, EmailConstants.TEXT_HTML);
			email.setCharset(EmailConstants.UTF_8);

			email.send();
		} catch (EmailException ex) {
			throw new RuntimeException("Sending email failed: " + ex.getMessage() + " ### " + ex.toString()
					+ " ### " + to_address + " " + to_name + " " + from_address + " " + from_name + " " +
subject + " " + message + " " + senderuser + " " + senderpass);
		}
	}
{noformat}

> javamail: sending email fails
> -----------------------------
>
>                 Key: TOMEE-1697
>                 URL: https://issues.apache.org/jira/browse/TOMEE-1697
>             Project: TomEE
>          Issue Type: Bug
>    Affects Versions: 1.7.3
>         Environment: Linux (Ubuntu 14.04.3 LTS), Oracle Java 1.8.0_66
>            Reporter: Tamás Greguss
>            Priority: Critical
>             Fix For: 1.7.4
>
>
> Sending email fails. javamail's Transport.send(...) function throws an exception. The
same code works fine with previous versions of TomEE which includes javamail 1.8.3. But TomEE
1.7.3 upgraded to javamail 1.9.0-alpha2 which does not work well.
> If in TomEE 1.7.3 lib folder I change the content of geronimo-javamail_1.4_mail-1.9.0-alpha-2.jar
file to the previous geronimo-javamail_1.4_mail-1.8.3.jar, it also works well.
> Here is the code that works fine with sendmail 1.8.3 in TomEE 1.7.1 but fails with sendmail.1.9.0-alpha2
in TomEE 1.7.3:
>  (This is a low level code only. But using apache commons email library which uses java.mail
in the background, also fails.)
> {code:title=MailSender.java|borderStyle=solid}
> public static void SendWithGMailSSL( String email_to, String subject, String text, String
email_from, final String senderuser, final String senderpass ) {
> 	Properties props = new Properties();
> 	props.put("mail.smtp.host", "smtp.gmail.com");
> 	props.put("mail.smtp.socketFactory.port", "465");
> 	props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
> 	props.put("mail.smtp.auth", "true");
> 	props.put("mail.smtp.port", "465");
> 	Session session;
> 	try {
> 		session = Session.getInstance(props, new javax.mail.Authenticator() {
> 			@Override
> 			protected PasswordAuthentication getPasswordAuthentication() {
> 				return new PasswordAuthentication(senderuser, senderpass);
> 			}
> 		});
> 	} catch (Exception e) {
> 		throw new RuntimeException(e);
> 	}
> 	try {
> 		Message message = new MimeMessage(session);
> 		message.setFrom(new InternetAddress(email_from));
> 		message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email_to));
> 		message.setSubject(subject);
> 		message.setText(text);
> 		Transport.send(message);
> 		//System.out.println("e-mail sending done.");
> 	} catch (MessagingException e) {
> 		throw new RuntimeException(e);
> 	}
> }
> {code}
> The calling of Transport.send(message) throws an exception:
> {noformat}
> javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Connection
error (java.io.IOException: Error connecting to smtp.gmail.com, 465))
> 	at javax.mail.Transport.send(Transport.java:163)
> 	at javax.mail.Transport.send(Transport.java:48)
> 	at com.gbit.lib.GBITMail.SendWithGMailSSL(GBITMail.java:136)
> 	at com.gbit.lib.GBITMail.SendMail(GBITMail.java:103)
> 	at com.gbit.efoglalo.test.UnitTestMB.testSendingEmailOld(UnitTestMB.java:503)
> 	at com.gbit.efoglalo.test.UnitTestMB$$OwbNormalScopeProxy0.testSendingEmailOld(com/gbit/efoglalo/test/UnitTestMB.java)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:497)
> 	at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
> 	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
> 	at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
> 	at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:88)
> 	at javax.faces.event.ActionEvent.processListener(ActionEvent.java:51)
> 	at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:420)
> 	at javax.faces.component.UICommand.broadcast(UICommand.java:103)
> 	at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1041)
> 	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:289)
> 	at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1415)
> 	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:765)
> 	at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
> 	at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
> 	at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
> 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> 	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> 	at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> 	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
> 	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
> 	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
> 	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
> 	at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> 	at org.omnifaces.filter.CacheControlFilter.doFilter(CacheControlFilter.java:226)
> 	at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
> 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
> 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
> 	at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
> 	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
> 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
> 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
> 	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
> 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
> 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
> 	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
> 	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
> 	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
> 	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
> 	at java.lang.Thread.run(Thread.java:745)
> Caused by: javax.mail.MessagingException: Connection error (java.io.IOException: Error
connecting to smtp.gmail.com, 465)
> 	at org.apache.geronimo.javamail.transport.smtp.SMTPConnection.protocolConnect(SMTPConnection.java:166)
> 	at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:165)
> 	at javax.mail.Service.connect(Service.java:274)
> 	at javax.mail.Service.connect(Service.java:91)
> 	at javax.mail.Service.connect(Service.java:76)
> 	at javax.mail.Transport.send(Transport.java:94)
> 	... 59 more
> Caused by: java.io.IOException: Error connecting to smtp.gmail.com, 465
> 	at org.apache.geronimo.javamail.util.MailConnection.createSocketFromFactory(MailConnection.java:408)
> 	at org.apache.geronimo.javamail.util.MailConnection.createSocket(MailConnection.java:504)
> 	at org.apache.geronimo.javamail.util.MailConnection.getConnectedSocket(MailConnection.java:322)
> 	at org.apache.geronimo.javamail.util.MailConnection.getConnection(MailConnection.java:274)
> 	at org.apache.geronimo.javamail.transport.smtp.SMTPConnection.protocolConnect(SMTPConnection.java:145)
> 	... 64 more
> Caused by: java.lang.InstantiationException
> 	at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
> 	at java.lang.Class.newInstance(Class.java:442)
> 	at org.apache.geronimo.javamail.util.MailConnection.createSocketFromFactory(MailConnection.java:355)
> 	... 68 more
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message