1 2 Previous Next 28 Replies Latest reply on Feb 28, 2014 4:55 AM by Simon Cigoj Go to original post
      • 15. Re: Unable to use Mailing with SSL StartTLS option
        Tomaž Cerar Master

        Hmm, strange then just dont define it...

        looking at javamail docs it should work the way i discribed....

        • 16. Re: Unable to use Mailing with SSL StartTLS option
          drobs Newbie

          I found this thread, because I have the same problem - STARTTLS mode doesn't work.

           

          This is because by setting ssl=true in the sub-system configuration, the mail Session object is created with both mail.smtp.ssl.enable=true and mail.smtp.starttls.enable=true.  Sun's Java Mail implementation sees that the first one is set and therefore expects the server socket to be running with SSL already.  If the port number isn't changed and a connection is made to port 25, the connection fails because the client attempts to negotiate the SSL straight away.  This obviously won't work.

           

          I see that Tomaz has created a new parameter 'tls', which I hope means that each Java Mail property can be set separately.  However, I'm not able to test with JBoss 7.2 at this time, so cannot confirm this.  I'm currently "stuck" on 7.1.1.Final.

           

           

          The second issue, with the from address is because the from parameter set within the JBoss sub-system config sets up the Session's mail.from property, which is only used by the SMTP transport.  When you set a 'from' address in the header of your MIME message, it is / can be completely different.  It is this latter one that the user will see in their mail client (or similar).

           

          Therefore, Anshu, it depends on what you want to achieve in terms of changing the sender's address.  Once set in the Session, you can't change it.  You could, if really necessary, pull the properties from the Session held in JNDI, change the mail.from property, then use those properties to create a new Session - although if you're doing authentication as well, you won't get the password in the Session properties, so would have to set it manually.  However, it kind of defeats the point really.

          • 17. Re: Unable to use Mailing with SSL StartTLS option
            Tomaž Cerar Master

            Hi guys,

             

            I have prepared 7.1.1 compatible mail module, that you can find in attachment.

            that way you will be able to to test it easier.

             

            Instalation is same as before.

             

            Let me know if everything works as it should.

             

            @Dave: you are right, this new version has now two separate flags to control ssl and tls.

             

             

            --

            tomaz

            • 18. Re: Unable to use Mailing with SSL StartTLS option
              drobs Newbie

              Thanks Tomaz, I can confirm that setting the tls attribute to true fixes the problem.

              1 of 1 people found this helpful
              • 19. Re: Unable to use Mailing with SSL StartTLS option
                Tomaž Cerar Master

                Thank you for confirmation.

                 

                I will make sure this fix comes to next release.

                 

                 

                --

                tomaz

                • 20. Re: Unable to use Mailing with SSL StartTLS option
                  marcelo.magalhaes Newbie

                  Dear friends, I found this topic and help me a LOT!!! But I am having a problem to setting the JavaMail JBOSS 7.1.1 using exchenge server to send email. Reading this topic I've found that 7.1.1 has a bug regarding the TLS. I used the patch provided by Tomaz Cerar, but I'm still having problems connecting to the exchange server. What server address I use? Which port (587, 993, 995)?

                   

                  My smtp server to exchange (i found this address in outlook configurations): pod51028.outlook.com

                  port: 587

                   

                  I try to use telnet to connect directly to the server in 587 port, but this port is not open. I could only connect (telnet) in 993 and 995 port. I test my code using other smtp server (i.e. Gmail) and works fine, so I think my java code is right, the problem is not to connect to my exchange server. Can someone help me?

                   

                  []s

                  Marcelo Magalhães

                  • 21. Re: Unable to use Mailing with SSL StartTLS option
                    Tomaž Cerar Master

                    Hi,

                     

                    can you post the configuration you are using (without un/pw ofcourse) so we can easier find what is wrong with it.

                     

                    also what version of app server are you using?

                     

                     

                    --

                    tomaz

                    • 22. Re: Unable to use Mailing with SSL StartTLS option
                      marcelo.magalhaes Newbie

                      The configurations...

                       

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

                                  <mail-session jndi-name="java:jboss/mail/MailService" debug="true" from="marcelo.magalhaes@snclavalinmarte.com.br">

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

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

                                      </smtp-server>

                                  </mail-session>

                              </subsystem>

                       

                       

                      and the socket config...

                       

                              <outbound-socket-binding name="mail-smtp">

                                  <remote-destination host="pod51028.outlook.com" port="993"/>

                              </outbound-socket-binding>

                       

                      The java code... just to be what I doing...

                       

                      ...


                      @Resource(mappedName = "java:jboss/mail/MailService")

                              private Session mySession;

                      ...

                              public String send()

                              {

                                  System.out.print("email");

                                  try

                                  {

                                        Message message = new MimeMessage(mySession);

                             

                                        message.setFrom(new InternetAddress((String) from.getValue())); <= IGNORE THIS, use default from user

                                        message.addRecipient(Message.RecipientType.TO, new InternetAddress((String) to.getValue()));

                                        message.setSubject((String) subject.getValue());

                                        message.setContent((String) body.getValue(), "text/plain");

                             

                                        Transport.send(message);

                             

                                        return "sucesso";

                                  }

                                  catch(Exception e)

                                  {

                                        e.printStackTrace();

                                  }

                                 

                                  return "failure";

                              }

                      • 23. Re: Unable to use Mailing with SSL StartTLS option
                        Tomaž Cerar Master

                        Hi,

                         

                        reading some docs about this and proper port for usage with TLS should be 587 and host smtp.live.com (but this could have changed recently)

                         

                         

                        can you try with that?

                         

                         

                        --

                        tomaz

                        • 24. Re: Unable to use Mailing with SSL StartTLS option
                          marcelo.magalhaes Newbie

                          Not work ... this is the stdout of eclipse when a click in send button:

                           

                          16:10:19,668 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) DEBUG: JavaMail version 1.4.4

                          16:10:19,690 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) DEBUG: successfully loaded resource: /META-INF/javamail.default.providers

                          16:10:19,694 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) DEBUG: Tables of loaded providers

                          16:10:19,698 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) 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]}

                          16:10:19,725 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) 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]}

                          16:10:19,749 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map

                          16:10:31,121 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) emailDEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

                          16:10:31,295 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) DEBUG SMTP: useEhlo true, useAuth true

                          16:10:31,300 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) DEBUG SMTP: useEhlo true, useAuth true

                          16:10:31,304 INFO  [stdout] (http-localhost-127.0.0.1-8080-2) DEBUG SMTP: trying to connect to host "smtp.live.com", port 587, isSSL false

                          16:10:31,316 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) javax.mail.MessagingException: Could not connect to SMTP host: smtp.live.com, port: 587;

                          16:10:31,322 ERROR [stderr] (http-localhost-127.0.0.1-8080-2)   nested exception is:

                          16:10:31,325 ERROR [stderr] (http-localhost-127.0.0.1-8080-2)           java.net.SocketException: Permission denied: connect

                          • 25. Re: Unable to use Mailing with SSL StartTLS option
                            marcelo.magalhaes Newbie

                            See above the print screen of www.office365.com configuration information to config others e-mail clients. This could help you to help me

                            • 27. Re: Unable to use Mailing with SSL StartTLS option
                              marcelo.magalhaes Newbie

                              Hi Tomaz, unfortunately, don´t work

                               

                              I add this line in standalone.bat file:

                               

                              rem Setup JBoss specific properties

                              set JAVA_OPTS=-Dprogram.name=%PROGNAME% %JAVA_OPTS%

                              rem Linha adicionada para inicializar o JBOSS em modo debug

                              set JAVA_OPTS="%JAVA_OPTS% -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"

                              rem Linha adicionada para resovler o problema da conexão SMTP

                              set JAVA_OPTS="%JAVA_OPTS% -Djava.net.preferIPv4Stack=true" <= HERE!!!

                               

                              And nothing.... I think the real problem is about server address/port...:

                              • 28. Re: Unable to use Mailing with SSL StartTLS option
                                Simon Cigoj Newbie

                                Mybe it could be helpful to someone. Today I neaded to send email via TLS, im using wildfly 8 final.

                                 

                                To get it working I had to set the property "mail.smtp.starttls.enable" to true to the mail session in java.

                                 

                                My config in standalone xml:

                                 

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

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

                                                <smtp-server outbound-socket-binding-ref="mail-smtp" tls="true" username="************" password="************"/>

                                            </mail-session>

                                        </subsystem>

                                .......................................

                                      <outbound-socket-binding name="mail-smtp">

                                            <remote-destination host="my.host.com" port="587"/>

                                        </outbound-socket-binding>


                                My java code:

                                 

                                 

                                public class EmailHandler {

                                 

                                    @Resource(mappedName="java:jboss/mail/Default")

                                    private Session mailSession;

                                   

                                  

                                    public void sendMail(){

                                      

                                        try {

                                          

                                            mailSession.getProperties().put("mail.smtp.starttls.enable", true);

                                          

                                            MimeMessage m = new MimeMessage(mailSession);

                                            Address from = new InternetAddress("from-mail");

                                            Address[] to = new InternetAddress[] {new InternetAddress("to-mail") };

                                           

                                            m.setFrom(from);

                                            m.setRecipients(Message.RecipientType.TO, to);

                                            m.setSubject("JBoss AS 7 Mail");

                                            m.setSentDate(new java.util.Date());

                                            m.setContent("Mail sent from JBoss AS 7","text/plain");

                                            Transport.send(m);

                                      

                                        } catch (javax.mail.MessagingException e) {

                                            e.printStackTrace();

                                        }

                                      

                                    }

                                      

                                }

                                 

                                Probbably it could be done alo trougs some configs but I havent found the way for now.  The posted solution works for me withowt problems. 

                                1 2 Previous Next