The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: Setup of Glassfish Email to use remote server and Port

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is answered.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 28 - Last Post: Aug 29, 2008 1:26 AM by: cn_thesky
factor3

Posts: 13
Setup of Glassfish Email to use remote server and Port
Posted: Mar 21, 2008 2:58 PM
 
  Click to reply to this thread Reply

Greetings:

I am attempting to use the Javamail Session resource in Glassfish to send email using an SMTP server that is *not* local to the machine running Glassfish.

I have gone through the (incredibly vague) instructions for setting up a Javamail Session on Glassfish, but all those instructions do is suggest that I set properties using properties known in Javamail. This is somewhat OK, I guess, but the Javamail properties I know about seem to be ignored by the server!

My attempts to put authentication information (using smtp.mail.username and smtp.mail.password) are failing. The server I am attempting to use communicates on a port other than 25; my attempts to get Glassfish to stop attempting to use that port have also failed.

Worse: Glassfish keeps insisting on looking on localhost for the SMTP server, even though I keep trying to get it to go to a remote one.

Glassfish, frankly, does not appear to be capable of handling email unless the server is on the machine, using the standard port, and does not implement authentication. This is a major inadequacy (the security issues alone will make Glassfish's handling of email inadequate!) that could well force me to move to JBoss 5 or some other application server!

Could someone either give an example of how to set up Glassfish so that a client can use a remote SMTP server with authentication, or confirm to me that this application server is indeed incapable of offering email sessions with any flexibility so that I won't waste my time on it any more???

Thanks in advance for any help on this matter.

dabaner

Posts: 8
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 21, 2008 6:43 PM   in response to: factor3
 
  Click to reply to this thread Reply

Not sure what you are going to do with the mailSession on Glassfish, but I am pretty sure it works with remte SMTP. What I did was simply creating Java mail Session on Glassfish admin console, e.g. by specifying Mail Host, Default User, Default Return Address ant taking all default settings on others. Then you can use it in you application. You can find more details about my uses and discussion from this link, http://forums.java.net/jive/thread.jspa?threadID=37837&tstart=0.

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 24, 2008 10:16 AM   in response to: dabaner
 
  Click to reply to this thread Reply

Greetings:

Thanks for your reply, but it does not help with my particular problem.

First, your setup is very different from mine. I am not, for example, using Spring anywhere. This is a pure Glassfish setup.

Second: the failure that I am getting is very different from yours. While I, too, am setting up a Java mail Session on the console, and specifying the email host, default user, and default return address, the Glassfish container is not going to the host I am specifying.

The precise failure I am getting is:

WARNING: javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at factor3.web.bbase.gui.query.MailBean.sendBorrowRequest(MailBean.java:91)
at factor3.web.bbase.gui.query.BorrowPanel.initiateBorrowing(BorrowPanel.java:138)
at factor3.web.bbase.gui.query.BorrowPanel.actionPerformed(BorrowPanel.java:186)
at thinwire.ui.EventListenerImpl.fireEvent(EventListenerImpl.java:314)
at thinwire.ui.EventListenerImpl.fireAction(EventListenerImpl.java:246)
at thinwire.ui.AbstractComponent.fireAction(AbstractComponent.java:159)
at thinwire.render.web.ComponentRenderer.componentChange(ComponentRenderer.java:351)
at thinwire.render.web.EventProcessor.processUserActionEvent(EventProcessor.java:132)
at thinwire.render.web.EventProcessor.run(EventProcessor.java:88)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:430)
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:585)
at com.sun.enterprise.server.ss.provider.ASPlainSocketImpl$2.run(ASPlainSocketImpl.java:419)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.enterprise.server.ss.provider.ASPlainSocketImpl._invoke(ASPlainSocketImpl.java:416)
at com.sun.enterprise.server.ss.provider.ASPlainSocketImpl.connect(ASPlainSocketImpl.java:288)
at com.sun.enterprise.server.ss.provider.ASClientSocketImpl.connect(ASClientSocketImpl.java:267)
at java.net.Socket.connect(Socket.java:516)
at java.net.Socket.connect(Socket.java:466)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
... 15 more

The problem is: (a) for some reason Glassfish thinks the SMTP server is on Localhost -- when it is not and (b) it thinks it needs to use Port 25, which it does not.

I need to know how to set it so that it goes to another machine to access the SMTP server and I also need to know how to make it use a specified port (other than Port 25). I also need to know how to set the server to send the SMTP server the proper username and password so that the email can be sent.

Could you or someone please give an example of how to do these things??? Or am I going to need to switch Application Servers???

whartung

Posts: 634
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 24, 2008 11:19 AM   in response to: factor3
Helpful
  Click to reply to this thread Reply

You should post your properties.

We use a remote server, and it works fine.

From the console:

Mail Host: xxx.com

User Name: abc

Default Return Address: abc@xxx.com

Status: Enabled

Advanced:

Store Protocol: imap

Store Protocol Class: com.sun.mail.imap.IMAPStore

Transport Protocol: smtp

Transport Protocol Class: com.sun.mail.smtp.SMTPTransport

That's it, we only use it for outgoing mail.

Sounds like you may be using a different port than stock SMTP? (Cuz smtp's default port IS 25...)

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 24, 2008 12:26 PM   in response to: whartung
 
  Click to reply to this thread Reply

Actually:

Yes, the place where I am emailing from apparently does not use Port 25. It uses Port 993.

The properties are below:

JNDI Name: BBMail
Mail Host: mail.ll.mit.edu
Default user <my user name>
Default return address: <my email address>
Status: Enabled box is checked

Advanced
.
.
.
Transport Protocol: smtp
Transport Protocol Class: com.sun.mail.smtp.SMTPTransport


Note: the Mail Host setting points to the machine that handles all emails for my location. The mail server is (unfortunately) Exchange 2007 (I have no control over this; some genius in Management decided to switch us over to this POS). Exchange resides on a machine that is different from the machine running Glassfish. It uses Port 993. This server works (relatively) well with Thunderbird; the settings in Thunderbird are the same as those in Glassfish -- except that Glassfish does not supply a means of setting the Port to the correct number. Another thing I note: my mail server is set to use SSL in Thunderbird. There appears to be no such setting in Glassfish.

Note also that despite the fact that I am setting the Host to the appropriate place, Glassfish still insists on attempting to use *localhost* to access the smtp server. It is as if Glassfish is ignoring the fact that I am setting it to look at another host!

It is looking more and more like Glassfish is simply incapable of operating properly in this environment.

whartung

Posts: 634
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 24, 2008 3:30 PM   in response to: factor3
Helpful
  Click to reply to this thread Reply

You need to hit up the JavaMail docs to learn what extra properties and what not you may need.

For example, mail.smtp.port is the property you would set to set the SMTP port, and you can add that directly to the extra properties on the JavaMail resource.

GF will pass those through untouched to JavaMail so it can do whatever it wants to do.

I dunno how SSL is supported via JavaMail, but there is a class: com.sun.mail.smtp.SMTPSSLTransport

That looks suspiciously helpful.

Basically, I'm betting your solution (assuming is exists) is in the JavaMail docs. GF is just providing an easy to use console for the common case. Since you can put anything you want in the properties of the connector, you should be able to bend JavaMail to your will appropriateluy. GF isn't getting in the way here.

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 6:02 AM   in response to: whartung
 
  Click to reply to this thread Reply

Actually:

I have already looked at the Javamail docs (as indicated in another post in this forum) and actually set the "mail.smtp.port" value to 993 (sorry; I forgot to put that setting in my previous post).

That is one of the things that is perplexing about this problem. Despite the fact that I did add a property called "mail.smtp.port" which I *did* set to 993, Glassfish insists upon attempting to use Port 25:

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
...etc

In other words, Glassfish is not passing anything to Javamail, or if it is, it is still trying to pass it through the wrong port!

As for theSMTPSSLTransport class: I was unaware of this class and did attempt to use it for the transport protocol. It made no difference, though; Glassfish still insists upon attempting to access email through "localhost" and Port 25. It doesn't seem to matter what is used as a transport if the blasted system keeps ignoring all the other settings!

Dick Davies
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 6:03 AM   in response to: factor3
  Click to reply to this thread Reply

Sounds very much to me that it's defaulting to 25 and localhost.
Does it seem to take notice of *any* of your settings?

I didn't have any trouble setting up a javamail jndi resource myself.

On Tue, Mar 25, 2008 at 1:02 PM, <glassfish@javadesktop.org> wrote:
> Actually:
>
> I have already looked at the Javamail docs (as indicated in another post in this forum) and actually set the "mail.smtp.port" value to 993 (sorry; I forgot to put that setting in my previous post).
>
> That is one of the things that is perplexing about this problem. Despite the fact that I did add a property called "mail.smtp.port" which I *did* set to 993, Glassfish insists upon attempting to use Port 25:
>
> javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
> nested exception is:
> java.net.ConnectException: Connection refused
> at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
> at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
> at javax.mail.Service.connect(Service.java:288)
> at javax.mail.Service.connect(Service.java:169)
> ...etc
>
> In other words, Glassfish is not passing anything to Javamail, or if it is, it is still trying to pass it through the wrong port!
>
> As for theSMTPSSLTransport class: I was unaware of this class and did attempt to use it for the transport protocol. It made no difference, though; Glassfish still insists upon attempting to access email through "localhost" and Port 25. It doesn't seem to matter what is used as a transport if the blasted system keeps ignoring all the other settings!
> [Message sent by forum member 'factor3' (factor3)]
>
> http://forums.java.net/jive/thread.jspa?messageID=265663
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>



--
Rasputnik :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


writtmeyer

Posts: 71
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 6:38 AM   in response to: factor3
 
  Click to reply to this thread Reply

There has been another issue in this forum a few days ago:

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

It seems that properties are either generally ignored or at least the important ones.

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 8:54 AM   in response to: writtmeyer
 
  Click to reply to this thread Reply

Yes, actually that is the issue I looked over before posting mine. That is where I discovered that (supposedly) using Javamail settings was supposed to enable the modification of Glassfish's port and authentication settings.

Apparently, the Glassfish documentation is incorrect, or there is clearly a bug in Glassfish V2. Or perhaps it is an inadequacy related to its implementation of Javamail resources.

It is obvious from the fact that there are no "standard" settings for authentication or port numbers that whoever dreamed up the Javamail resource did not take into account the many ways that such resources would be used from within an application server. I do not believe that the person or persons who came up with the settings for Javamail resources under Glassfish were even familiar with the Javamail API or how it is used in servlets, JSPs or anywhere else!

Nevertheless: it is becoming more painfully obvious that Glassfish in its current form is simply not equipped to produce "real world" Javamail sessions. This is unfortunate, because it is providing yet another example of how Sun is great at coming up with nice ideas for standards and interfaces, yet is extremely poor at implementing them.

At this point, unless someone discovers a solution to this problem, I am going to report this behavior to Sun as a bug (let's see how responsive they are to that!). Once I have placed a bug report in the appropriate place, I am dumping this app server and switching to JBoss 5.

Dick Davies
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 9:05 AM   in response to: factor3
  Click to reply to this thread Reply

On Tue, Mar 25, 2008 at 3:54 PM, <glassfish@javadesktop.org> wrote:

> At this point, unless someone discovers a solution to this problem, I am going to report this behavior to Sun as a bug (let's see how responsive they are to that!).

In my experience, terrifying efficient. I had 3 bugs fixed in about 2
days while trying to get roller
working on glassfish.

> Once I have placed a bug report in the appropriate place, I am dumping this app server and switching to JBoss 5.

Up to you, seems a bit hasty to me though.

--
Rasputnik :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net


whartung

Posts: 634
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 10:41 AM   in response to: factor3
 
  Click to reply to this thread Reply

I'm just really baffled simply because we have no problems. Truth, we don't specify a port, but we do specify a different host, and it Just Works.

There may well be a bug, but from what I can tell it really is simply a basic "wrapper" UI surrounding populating properties for JavaMail, and then punting it up stream. It doesn't really need to to much of anything, one of those "to simple to fail" things.

Yea, glancing at the code, it seems pretty brain dead to me.

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 11:31 AM   in response to: factor3
 
  Click to reply to this thread Reply

I've been following this thread but I don't have any answers for you right now. It will take me a few days to look into this and see what is going on.

On the off chance this is related to another issue I investigated yesterday, can you tell me how your application retrieves the javamail resource from the server? (e.g. resource injection, jndi lookup, etc.) If using JNDI, what exactly does your lookup call look like?

In the future, if you need urgent or priority solutions, for a faster response, please consider the support options on this page: http://www.sun.com/software/products/appsrvr/support.jsp.

Peter Williams
Staff Engineer, Sun Microsystems

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 6:11 PM   in response to: factor3
Correct
  Click to reply to this thread Reply

In the issue you filed (https://glassfish.dev.java.net/issues/show_bug.cgi?id=4498), you show your user defined property names as dot-separated strings.

GlassFish requires the first delimiter to be a hyphen (e.g. "mail-smtp-host") or the property will be ignored. See the Developer's Guide at http://docs.sun.com/app/docs/doc/819-3672/beaow?a=view under "JavaMail Session Properties".

(BTW, I noted the examples at the bottom of that page DO NOT do this, sorry about that, I made a note of it for docs to correct.)

So, if you fix your property definitions, does it work and if not, please provide more information.

Peter Williams
Staff Engineer, Sun Microsystems

smuehlst

Posts: 36
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 26, 2008 2:27 PM   in response to: peterwx
 
  Click to reply to this thread Reply

Peter,

the hyphens in the property names are really an amazing idea to confuse users of the GlassFish admin console!

I would never have looked into the "Developer's Guide" for information on how to configure the JavaMail session... I looked into the "Administrator's Guide", and there is the section "Creating a JavaMail Session", and this section does not mention the hyphens at all, but it refers the JavaMail API documentation for a list of the additional properties.

I also opened the help in the GlassFish admin console when editing a JavaMail resource, and this also does not mention the hyphens. It is more or less a copy of the corresponding section in the "Administrator's Guide".

Regarding your remark about the examples at the bottom of the page: I think there it is correct not to use the hyphens in property names, because the examples use the JavaMail API directly, and there the property names are written with dots and not with hyphens.

Regards
Stephan

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 26, 2008 2:42 PM   in response to: smuehlst
 
  Click to reply to this thread Reply

I completely agree. I don't know why it uses hyphens and I can't think of a reason to require this. (Note only the first delimiter _must_ be a hyphen, the remainder can be dots or hyphens).

I will see if I can get future server versions upgraded to accept dots delimiters as well for custom properties such as these. Might not be until V3 though.

Thank you for the reference to additional confusing documentation. I will see what I can do.

Peter Williams
Staff Engineer, Sun Microsystems

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 26, 2008 3:40 PM   in response to: peterwx
 
  Click to reply to this thread Reply

Changing the property names to dash- delimited strings did the trick -- at least as far as getting the server to pay attention to my port setting.

I am having other failures now, but at least Glassfish is now going to the correct server and port. I suspect the other problems involve the fact that it is requiring an SSL connection and that it is going to an Exchange server. Correct me if I am wrong, but I do not believe that there are any transport classes that enable us to send Javamail through an Exchange 2007 server.

As for the fix, frankly, I agree with you and the others: requiring a hyphen in a "Javamail" property name is ridiculous. It serves no useful purpose and, in my case, caused a great deal of unnecessary confusion.

Actually, as I suggested in my bug report (which I will be removing since it really isn't a bug) the requirement for a seperate set of Javamail "custom properties" makes even less sense. Isn't the purpose of this resource to create sessions that are used to send messages using Javamail??? Why don't you folks simply make the so- called "Javamail" properties (like port number, whether or not authentication is used, etc) standard properties of the Javamail Resource??? Let them have defaults the same way that your Store Protocol class, your Transport Protocol, and your Transport protocol class does, but make them standard like your Mail Host, Default User, and Transport Protocol properties.

It is totally illogical to force people to use special "custom" Javamail properties -- entered in a format not like "regular" Javamail properties -- in order to properly set up sessions that are going to be used with Javamail! I could almost understand if such resources were going to be used with something other than Javamail, but these are *JavaMail Session* resources! Why don't you just cover all the properties associated with Javamail on the page??? Doing so isn't just a nice idea; it is half- decent user- interface design!

Ah, well: I will now get off my soapbox and get back to work. Thanks for your assistance...

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 27, 2008 12:11 PM   in response to: factor3
 
  Click to reply to this thread Reply

I've run JavaMail tests against Exchange Server before (2003 version?). I wasn't able to determine if the tests included SMTP or not. But ES 2007 docs say they support SMTP so modulo bugs and configuration issues, it seems like it ought to work.

I started working on an SMTP Authentication in JavaEE example. It won't be ready for a while though.

Finally, I filed https://glassfish.dev.java.net/issues/show_bug.cgi?id=4516 to handle documentation issues related to this.

I also filed enhancement https://glassfish.dev.java.net/issues/show_bug.cgi?id=4515 to make these properties more consistent.

Anyone is encouraged to add additional commentary to these issues for anything I missed. Please keep comments on topic (and file new issues for off-topic bugs or suggestions).

Peter Williams
Staff Engineer, Sun Microsystems

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Apr 1, 2008 7:45 PM   in response to: peterwx
 
  Click to reply to this thread Reply

You are likely right. It seems that I can get to the mail server.

I do have one problem, though: the authentication settings don't seem to work. Somehow the server is failing to authenticate me, despite the fact that I have set the correct username and password.

Is there anything special I need to do in order to make this work?

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Apr 1, 2008 8:55 PM   in response to: factor3
 
  Click to reply to this thread Reply

Passwords are not read from properties. I've done a little research so far and I'm pretty sure GlassFish doesn't manage this part for you. You will have to do the authentication yourself, possibly via transport.connect(...).

I have not had any further time to spend on the example I mentioned though so I can't give a more detailed answer yet.

Peter Williams
Staff Engineer, Sun Microsystems

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Apr 2, 2008 9:26 AM   in response to: peterwx
 
  Click to reply to this thread Reply

No problem.

Maybe I can help make the example.

Here is what I have for attempting to send an email:
@Resource(name = "<named service>",type=Session.class)
Session theSession;


boolean success = false;

try
{
InitialContext ctx = new InitialContext();
theSession = (Session )ctx.lookup("java:comp/env/<named service>");
Transport trans = theSession.getTransport("smtp");
Message msg = new MimeMessage(theSession);
msg.setRecipient(Message.RecipientType.TO,new InternetAddress("<Destination>"));
msg.setSubject("Testing... ");
msg.setText("This is just a test message!");

trans.connect("<username>","<password>");
success = true;
}
catch(NamingException nex)
{
nex.printStackTrace();
}
catch(AddressException addr)
{
addr.printStackTrace();
}
catch(MessagingException mex)
{
mex.printStackTrace();
}
return(success);

When I attempt to connect to the Exchange server, I get the following failure:

WARNING: javax.mail.MessagingException: Could not connect to SMTP host: nlb-exchange.llan.ll.mit.edu, port: 993;
nested exception is:
java.net.SocketException: Unconnected sockets not implemented
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:189)
at factor3.web.bbase.gui.query.MailBean.sendBorrowRequest(MailBean.java:99)
at factor3.web.bbase.gui.query.BorrowPanel.initiateBorrowing(BorrowPanel.java:138)
at factor3.web.bbase.gui.query.BorrowPanel.actionPerformed(BorrowPanel.java:186)
at thinwire.ui.EventListenerImpl.fireEvent(EventListenerImpl.java:314)
at thinwire.ui.EventListenerImpl.fireAction(EventListenerImpl.java:246)
at thinwire.ui.AbstractComponent.fireAction(AbstractComponent.java:159)
at thinwire.render.web.ComponentRenderer.componentChange(ComponentRenderer.java:351)
at thinwire.render.web.EventProcessor.processUserActionEvent(EventProcessor.java:132)
at thinwire.render.web.EventProcessor.run(EventProcessor.java:88)
Caused by: java.net.SocketException: Unconnected sockets not implemented
at javax.net.SocketFactory.createSocket(SocketFactory.java:97)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:225)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
... 13 more


I believe that this exception is being caused because I the Exchange Server is using the SSL Transport instead of an "ordinary" transport, because if I don't get the Transport from my Session (simply do a Transport.send()) I get the authentication failure.

I think I need to somehow get a Transport that will use the correct means (an instance of the com.sun.mail.smtp.SMTPSSLTransport class) to connect to the SMTP service. Is there any way to do this?

Please advise.

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Apr 2, 2008 10:43 AM   in response to: factor3
 
  Click to reply to this thread Reply

Which JDK are you using? If it's Sun's JDK, are you using a different JSSE provider than the one that comes with the JDK?

SSLNotes.txt from the separate javamail 1.4.1 distribution ( http://java.sun.com/products/javamail/ ) might be helpful here. You might also find this forum thread helpful: http://forum.java.sun.com/thread.jspa?forumID=43&threadID=701799

Since your code is running inside a JavaEE container, some of the above advice may not apply or may apply differently (hence why I wanted to write an example specifically for containers).

Peter Williams
Staff Engineer, Sun Microsystems

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Apr 3, 2008 3:39 PM   in response to: peterwx
 
  Click to reply to this thread Reply

I am using JDK 1.5, from Sun.

I have not specified any specific JSSE Provider, so I am assuming that the one I am using is the one that came with the SDK.

If this assumption is wrong, please let me know.

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Apr 3, 2008 4:55 PM   in response to: factor3
 
  Click to reply to this thread Reply

That assumption (about JSSE for Sun's JDK) should be correct.

Can you try smtps instead, e.g.

Transport trans = theSession.getTransport("smtps");

You probably also need to change your resource's smtp properties to use "smpts" as well.

When you start w/ smtp, it is probably using TLS to switch a regular socket to SSL and something is falling down somewhere. (Debugging the connection code might indicate the responsible party and the reason for the socket failure, but I have run out of speculative ideas at this point). Using smtps directly may bypass all this trouble.

Peter Williams
Staff Engineer, Sun Microsystems

factor3

Posts: 13
Re: Setup of Glassfish Email to use remote server and Port
Posted: Apr 4, 2008 10:19 AM   in response to: peterwx
 
  Click to reply to this thread Reply

We think alike.

I actually did try switching to SMTPS, doing exactly what you suggested prior to my last post.

For some weird reason, though, the system no longer seems to use the correct port. But then, that could be because I guessed at the smtps property for setting the port.

My first attempt, I left the mail properties as they were, just changing the transport from smtp to smtps. The transport attempted to connect to the wrong port.

Then I added the property: mail-smtps-port and set it to my port number. For some reason my port number was still ignored.

Am I adding the wrong property for smtps?

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Apr 4, 2008 3:09 PM   in response to: factor3
 
  Click to reply to this thread Reply

That is the correct property name. I may have some time to look at it later today, but not right now.

Peter Williams
Staff Engineer, Sun Microsystems

peterwx

Posts: 30
Re: Setup of Glassfish Email to use remote server and Port
Posted: Jul 1, 2008 4:42 PM   in response to: factor3
 
  Click to reply to this thread Reply

Hi there, I don't know if you ever got this working but I finally was able to dig into it. From looking at issue 4498, it seems there probably were some properties missing that you needed. I'm guessing you need to add the following to your mail resource to resolve the socket issues you ran into:

    <property name="mail-smtps-starttls-enable" value="true"/>
    <property name="mail-smtps-socketFactory-port" value="465"/>
    <property name="mail-smtps-socketFactory-class" value="javax.net.ssl.SSLSocketFactory"/>
    <property name="mail-smtps-socketFactory-fallback" value="false"/>


(or use "mail-smtp-..." prefix if you specified that protocol). I'm a bit unclear on the port though - you specified 993 in issue 4498 - that's the IMAP SSL port. 465 is the SMTP SSL port, but maybe Exchange is a little weird... I believe the socket factory port should be the same value you specified for "mail-smtps-port"

The following mail resource + code block works to send email via GMail SMTP SSL (if you put in valid username/password of course). Note - the password field does not have to be in the resource, but could come from the servlet session, etc. If you do store a password in the resource, note this is stored as plain text in domain.xml, so you probably want to secure it via the password alias mechanism. See http://wiki.glassfish.java.net/attach/GlassFishAdministrationPages/aliased-passwords.html

    <mail-resource debug="true" enabled="true" from="${youruserid}@gmail.com" 
            host="smtp.gmail.com" jndi-name="mail/gmailSession" object-type="user" 
            store-protocol="imaps" store-protocol-class="com.sun.mail.imap.IMAPStore"
            transport-protocol="smtps" transport-protocol-class="com.sun.mail.smtp.SMTPTransport"
            user="${youruserid}">
        <description>GMail Mail Resource</description>
        <property name="mail-smtps-host" value="smtp.gmail.com"/>
        <property name="mail-smtps-port" value="465"/>
        <property name="mail-smtps-auth" value="true"/>
        <property name="mail-smtps-user" value="${youruserid}"/>
        <property name="mail-smtps-password" value="${yourpassword}"/>
        <property name="mail-smtps-starttls-enable" value="true"/>
        <property name="mail-smtps-socketFactory-port" value="465"/>
        <property name="mail-smtps-socketFactory-class" value="javax.net.ssl.SSLSocketFactory"/>
        <property name="mail-smtps-socketFactory-fallback" value="false"/>
    </mail-resource>
 
// Servlet code...
 
    @Resource(name = "mail/gmailSession")
    private Session mailSession;
 
    /** email = recipient@their_server
     *  subject, body = message text
     */
    void sendMail(String email, String subject, String body) throws MessagingException, NamingException {
        // username and password could come from anywhere, e.g. servlet session, etc.
        Properties props = mailSession.getProperties();
        String username = (String) props.get("mail.smtps.user");
        String password = (String) props.get("mail.smtps.password");
 
        MimeMessage message = new MimeMessage(mailSession);
        message.setSubject(subject);
        message.setRecipients(javax.mail.Message.RecipientType.TO, javax.mail.internet.InternetAddress.parse(email, false));
        message.setText(body);
        message.saveChanges();
 
        Transport transport = mailSession.getTransport("smtps");
        try {
            transport.connect(username, password);
            transport.sendMessage(message, message.getAllRecipients());
        } finally {
            transport.close();
        }
    }


Hope this helps...

Peter Williams
Staff Engineer, Sun Microsystems

cn_thesky

Posts: 1
Re: Setup of Glassfish Email to use remote server and Port
Posted: Aug 29, 2008 1:26 AM   in response to: peterwx
 
  Click to reply to this thread Reply

I use your code to write one simple servlet, to test send email. But it fails. However, I can send email when not in glassfish successfully. Should I set the properties:
javax.net.ssl.keyStorePassword?
jdk:1.6, glassfish: v2ur2. OS: XP

Exceptions:
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.6.0_06\jre\lib\javamail.address.map (The system cannot find the file specified)
Aug 29, 2008 3:45:28 PM com.sun.enterprise.server.logging.SystemOutandErrHandler$LoggingByteArrayOutputStream flush
WARNING: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:189)
at cn.thesky.mock.home.MailTest.sendMail(MailTest.java:41)
at cn.thesky.mock.home.MailTest.doGet(MailTest.java:77)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:380)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
Caused by: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
at javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:179)
at javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:186)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:223)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:163)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
... 35 more
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
at java.security.Provider$Service.newInstance(Provider.java:1245)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:220)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:147)
at javax.net.ssl.SSLContext.getInstance(SSLContext.java:125)
at javax.net.ssl.SSLContext.getDefault(SSLContext.java:68)
at javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:102)
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 com.sun.mail.util.SocketFetcher.getSocketFactory(SocketFetcher.java:262)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:150)
... 36 more
Caused by: java.security.UnrecoverableKeyException: Password must not be null
at sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:107)
at sun.security.provider.JavaKeyStore$JKS.engineGetKey(JavaKeyStore.java:38)
at java.security.KeyStore.getKey(KeyStore.java:763)
at com.sun.net.ssl.internal.ssl.SunX509KeyManagerImpl.<init>(SunX509KeyManagerImpl.java:113)
at com.sun.net.ssl.internal.ssl.KeyManagerFactoryImpl$SunX509.engineInit(KeyManagerFactoryImpl.java:48)
at javax.net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:239)
at com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl.getDefaultKeyManager(DefaultSSLContextImpl.java:170)
at com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl.<init>(DefaultSSLContextImpl.java:40)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at java.security.Provider$Service.newInstance(Provider.java:1221)
... 47 more

smuehlst

Posts: 36
Re: Setup of Glassfish Email to use remote server and Port
Posted: Mar 25, 2008 2:32 PM   in response to: writtmeyer
 
  Click to reply to this thread Reply

> There has been another issue in this forum a few days
> ago:
>
> http://forums.java.net/jive/thread.jspa?messageID=2642
> 33
>
> It seems that properties are either generally ignored
> or at least the important ones.

I had been the initiator of the referenced thread above. I'd like to point out that I did not mean to say that properties are ignored in general or that "the important ones" are ignored. That is not my experience, and I can confirm that JavaMail sessions work with remote hosts.

My specific difficulties are with SMTP authentication and JavaMail sessions. The question was whether it is possible to configure a JavaMail session with username and password in a way so that Glassfish sets up the javax.mail.Session object directly for SMTP authentication, without requiring additional actions for authentication by the application.

Regards
Stephan




 XML java.net RSS