users@glassfish.java.net

Send email to Gmail in glassfish

From: <glassfish_at_javadesktop.org>
Date: Thu, 24 Sep 2009 10:49:27 PDT

Hi, guys,

I am having issues sending email to Gmail in glassfishv3-prelude. Here is the exception:
INFO: DEBUG: setDebug: JavaMail version 1.4.1
INFO: DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
INFO: DEBUG SMTP: useEhlo true, useAuth true
INFO: DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
SEVERE: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
  nested exception is:
        java.net.SocketException: Unconnected sockets not implemented
SEVERE: at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
SEVERE: at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
SEVERE: at javax.mail.Service.connect(Service.java:288)
SEVERE: at javax.mail.Service.connect(Service.java:169)
SEVERE: at com.tekevolving.site.server.service.GoogleTest.send2(GoogleTest.java:53)
SEVERE: at com.tekevolving.site.server.service.GoogleTest.main(GoogleTest.java:32)
SEVERE: at com.tekevolving.site.server.service.AdminService.register(AdminService.java:107)
SEVERE: at com.tekevolving.site.server.presentation.pages.RegistrationPage.register(RegistrationPage.java:138)
SEVERE: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
SEVERE: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
SEVERE: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Here my code, please note this is a static method being invoked in glassfish container. I didn't use any conainter's facility, and if I
run the same static method from standalone java commmand line, it works. It looks like glassfish is in my way.

        public static void send_test() {
                Properties props = System.getProperties();
                props.put("mail.smtps.host", "smtp.gmail.com");
                props.put("mail.smtps.auth", "true");
                Session session = Session.getInstance(props, null);
                session.setDebug(true);
                Message msg = new MimeMessage(session);
                SMTPTransport t = null;
                try {
                        msg.setFrom();
                        msg.setRecipients(Message.RecipientType.TO,
                                        InternetAddress.parse("xxxx_at_gmail.com", false));
                        msg.setSubject("test subject");
                        msg.setText("test body");
                        msg.setHeader("X-Mailer", "tester");
                        msg.setSentDate(new Date());
                        t = (SMTPTransport)session.getTransport("smtps");
                        t.connect("smtp.gmail.com", "yyyyyy_at_gmail.com", "xxxxx");
                } catch (MessagingException e) {
                        e.printStackTrace();
                } finally {
                        try {
                                if (t != null)
                                        t.close();
                        } catch (MessagingException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                }
                System.out.println("Email has been send!!!!");
        }
        
I noticed lots of people over internet asking issues with email in glassfish, I don't see any concrete answers....

guys.. I really really need your help!!!

Thanks a lot in advance!
Lann
[Message sent by forum member 'taolu2000' (taolu2000_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=365597