1 2 Previous Next 28 Replies Latest reply on Feb 28, 2014 4:55 AM by Simon Cigoj

    Unable to use Mailing with SSL StartTLS option

    Anshu Gupta Newbie

      Hi,

       

      I am trying to use Java Mailing with Jboss 7.1.1.Final. I was successful in connecting through GMail but when I try to use my SMTP corporate exchange account it fails. It says No protocol supported by both client and server.

       

      My SMTP server is based on StartTLS. I have found that StartTLS was used to be set as properties in earlier Jboss like 4 & 5 but how to do that in Jboss 7. It only has SSL definition in its xsd.

       

      Any Ideas?

       

      Thanks,

      Anshu

        • 1. Re: Unable to use Mailing with SSL StartTLS option
          Tomaz Cerar Master

          Hi,

           

          did you try with ssl=true name of attribute was choosen poorly as it should be secure="true" but the basic workins are the same.

          if you enable ssl=true it will add STARTTLS to mail properties but, to be honest i havent got chance to test if that works.

           

          can you try it, and if it does not work, can you post me (can be PM) how your configuration looked like in previous versions of jboss.

          I will help me fix the code to take that into conseration and make it work for everyone

           

           

          --

          tomaz

          • 2. Re: Unable to use Mailing with SSL StartTLS option
            Anshu Gupta Newbie

            Hi Tomaz,

            I have tried putting ssl = true but it does not work for starttls.

             

            Earlier we used to put a property such as mail.smtp.ssl.starttls = enabled.

             

            Now JBOSS has moved to Subsystem arch, so do not know how to put that property explicitly as I have checked the xsd for Mail Session and it does not allow properties. It can just have SSL XML attribute in subsystem config.

             

            I think you need to make that change to allow that as most enterprise uses exchange which needs StartTLS. Time being I have moved to a test SMTP server but I need that pretty quickly for testing our system.

             

            Thanks.

            • 3. Re: Unable to use Mailing with SSL StartTLS option
              Tomaz Cerar Master

              hi,

               

              this is a bug in subsystem and must be fixed.

               

              currently subsystem sets property mail.smtp.starttls.enable=true

              which is what is specifed in documentation of javamail

              so you are sure that if you have property mail.smtp.ssl.starttls=enabled that it works for you?

               

              if that is the case i will fix subsystem and give you jar so you can test it yourself.

               

               

              --

              tomaz

              • 4. Re: Unable to use Mailing with SSL StartTLS option
                Anshu Gupta Newbie

                Thanks Tomaz.

                 

                I did try with ssl = true but somehow it did not work for me. Earlier I used to put it explicitly as by default it is false, if I am not wrong.

                But, now I do not know how to put that property. If that is by default if SSL = true then it should have worked. If not then its a BUG.

                 

                Please test if if possible, and let me know. Does anyone else faced this? I have searched a lot and I find that most people have not moved to Jboss 7 yet so a bit difficult.

                Meanwhile, I am trying with GMAIL and it works perfectly for me. Please let me know the results so that I can implement it with with my corporate exchange account as this needs to be done urgently.

                 

                Thanks,

                Anshu

                • 5. Re: Unable to use Mailing with SSL StartTLS option
                  Tomaz Cerar Master

                  Hi,

                   

                  i think i have found out the problem, but needs testing.

                  For gmail you can just use ssl=true and use gmail's ssl port(465) instead of TLS (587) one.

                   

                  will post again when i have some working solution.

                   

                  --

                  tomaz

                  • 6. Re: Unable to use Mailing with SSL StartTLS option
                    Anshu Gupta Newbie

                    Thanks a lot Tomaz.. I will wait for your solution. If you want I can even post the logs while I use TLS option.

                    I have successfully connected to Gmail SSL port i.e 465.

                     

                    Regards,

                    Anshu

                    • 7. Re: Unable to use Mailing with SSL StartTLS option
                      Tomaz Cerar Master

                      Hi,

                       

                      in attachment you can find updated version of mail subsystem that should have TLS working.

                       

                      unzip contents of mail-1.1.zip to jboss_home\modules\org\jboss\as\mail\main (remove / backup old files there)

                       

                      then change the configuration by this example

                      <subsystem xmlns="urn:jboss:domain:mail:1.1">

                          <mail-session jndi-name="java:/Mail" from="user dot name at domain dot tld">

                              <smtp-server outbound-socket-binding-ref="mail-smtp" tls="true">

                                  <login name="nobody" password="pass"/>

                              </smtp-server>

                              <pop3-server outbound-socket-binding-ref="mail-pop3"/>

                              <imap-server outbound-socket-binding-ref="mail-imap">

                                  <login name="nobody" password="pass"/>

                              </imap-server>

                          </mail-session>

                          <mail-session debug="true" jndi-name="java:jboss/mail/Default">

                              <smtp-server outbound-socket-binding-ref="mail-smtp"/>

                          </mail-session>

                      </subsystem>

                       

                      be alert that version of subsytem is 1.1 (it was 1.0) and that you have new atribute tls="true" tls and ssl attribute are mutualy exclusive, so you can only have tls or ssl enabled.

                       

                      let me know if it works for you now.

                       

                      --

                      tomaz

                      • 8. Re: Unable to use Mailing with SSL StartTLS option
                        Anshu Gupta Newbie

                        I am getting following error when doing this-

                         

                        I deleted all the old contents and copied the new modules of mail1.1

                         

                        18:45:57,004 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA

                        18:45:57,208 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA

                        18:45:57,255 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting

                        18:45:57,987 ERROR [org.jboss.as.controller.management-operation] JBAS014612: Operation ("parallel-extension-add") failed - address: ([]): java.lang.RuntimeException: JBAS014670: Failed initializing module org.jboss.as.mail

                            at org.jboss.as.controller.extension.ParallelExtensionAddHandler$1.execute(ParallelExtensionAddHandler.java:99) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:385) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:272) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:200) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:149) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:190) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.server.ServerService.boot(ServerService.java:291) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.server.ServerService.boot(ServerService.java:266) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_05]

                        Caused by: java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: org.jboss.as.controller.ExtensionContext.registerSubsystem(Ljava/lang/String;III)Lorg/jboss/as/controller/SubsystemRegistration;

                            at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source) [rt.jar:1.7.0_05]

                            at java.util.concurrent.FutureTask.get(Unknown Source) [rt.jar:1.7.0_05]

                            at org.jboss.as.controller.extension.ParallelExtensionAddHandler$1.execute(ParallelExtensionAddHandler.java:91) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            ... 9 more

                        Caused by: java.lang.NoSuchMethodError: org.jboss.as.controller.ExtensionContext.registerSubsystem(Ljava/lang/String;III)Lorg/jboss/as/controller/SubsystemRegistration;

                            at org.jboss.as.mail.extension.MailExtension.initialize(MailExtension.java:50)

                            at org.jboss.as.controller.extension.ExtensionAddHandler.initializeExtension(ExtensionAddHandler.java:88) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.controller.extension.ParallelExtensionAddHandler$ExtensionInitializeTask.call(ParallelExtensionAddHandler.java:127) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at org.jboss.as.controller.extension.ParallelExtensionAddHandler$ExtensionInitializeTask.call(ParallelExtensionAddHandler.java:113) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                            at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) [rt.jar:1.7.0_05]

                            at java.util.concurrent.FutureTask.run(Unknown Source) [rt.jar:1.7.0_05]

                            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_05]

                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_05]

                            at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_05]

                            at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.0.0.GA.jar:2.0.0.GA]

                         

                        18:45:58,000 FATAL [org.jboss.as.server] JBAS015957: Server boot has failed in an unrecoverable manner; exiting. See previous messages for details.

                        18:45:58,008 INFO  [org.jboss.as] JBAS015950: JBoss AS 7.1.1.Final "Brontes" stopped in 1ms

                        • 9. Re: Unable to use Mailing with SSL StartTLS option
                          Tomaz Cerar Master

                          I see,

                           

                          new version of subsystem is based on 7.2 codebase and needs few new things to be present in core.

                           

                          can you try with 7.2 nightly build and put extension into it. it should work, at least server will start with it

                           

                           

                          --

                          tomaz

                          • 10. Re: Unable to use Mailing with SSL StartTLS option
                            Anshu Gupta Newbie

                            I am afraid I cannot do it as my application cannot move to 7.2 which is still in dev stage. We need to use 7.1.1.Final only.

                            Can it not work in that?

                            Any workarounds?

                             

                            Please raise a JIRA issue against it.

                             

                            Thanks a lot Tomaz for your answer.

                             

                            -Anshu

                            • 11. Re: Unable to use Mailing with SSL StartTLS option
                              Tomaz Cerar Master

                              Hi,

                               

                              can you just try if TLS works for you even in 7.2.x server, if i get confirmation there are ways to provide updated mail subsystem also for 7.1.

                              but i wont start doing backporting without confirmation

                               

                               

                              --

                              tomaz

                              • 12. Re: Unable to use Mailing with SSL StartTLS option
                                Anshu Gupta Newbie

                                Hi Tomaz,

                                 

                                Will definitely try it out. Can you give me link from where to download and which nightly build to get.

                                Also, another requirement I had.

                                Is it possible to change the mail sender's address dynamically?

                                I changed the param in my code for the fromAddress part but still it takes the mail id configured in Mail session. Any pointers?

                                 

                                Thanks for all your help.

                                 

                                - Anshu

                                • 13. Re: Unable to use Mailing with SSL StartTLS option
                                  Tomaz Cerar Master

                                  Hi,

                                   

                                  you can find nightly builds here https://community.jboss.org/thread/167590

                                   

                                  You should be able change from address in your code, the "from" that you provide in configuration is just default value.

                                   

                                  And when you construct MailMessage you can define any from address you like.

                                  given that you use low level api for sending mail code would be something like this

                                  Message msg = new MimeMessage(session);

                                          try {

                                              InternetAddress addressFrom = new InternetAddress("Tomaz Cerar<name dot surname at domain dot tld>");

                                              msg.setFrom(addressFrom);

                                              msg.setRecipients(Message.RecipientType.TO, new Address[]{new InternetAddress("Anshu Gupta<name dot surname at domain dot tld>")});

                                              msg.setSubject("Test subject");

                                              msg.setContent("Mail content", "text/plain");

                                              Transport.send(msg);

                                          } catch (Exception e) {

                                              log.error("could not send mail", e);

                                          }

                                   

                                  --

                                  tomaz

                                  • 14. Re: Unable to use Mailing with SSL StartTLS option
                                    Anshu Gupta Newbie

                                    Ok. I will take a look at the nightly build.

                                    I am using the same code but it does not work. Mail address defined in standalone.xml is taken irrespective of setting from address.

                                     

                                    Thanks,

                                    Anshu

                                    1 2 Previous Next