Sorry missed your reply...
Thanks for showing us the code and Aaaarg! you using a framework... but, its
ok, the tomcat guys are just much nicer than those in Springs mailing list,
hey!... ha ha.
I avoid frameworks, but I had a quick look... seems like they store the
session object in an EJB container and let you inject it into any servlet...
or maybe its just a common class loader instance... doesnt really matter.
Just wanted to say that "your" code seems to be thread safe, but I seem to
remember and I cant remember where I read it, that if you set the FROM
attribute in different threads... which will happen on multiple requests...
then each one should have its own session object.
So... I think you have two choices if it happens again....
1) Set up your own session object... this will let you control the
properties and you can stay away from default system properties which I
think is inherently buggy... and then inject that into the the framework....
I'm not sure but I have a feeling that mailSender class will allow you to
set a session... just figure out how, on that framework... then I think the
locking behaviour will not reoccur.
2) This is more of a question... but when I looked at the framework code, it
seems to be synchronous... ie the user will wait in the browser until the
mail is sent and the request returns...
So I imagine your problems start with a user moaning at u.
Another way is to take that code and stick it in a background thread... ie
its just one mail session running and pumping out emails... and the user
mail is simply Q'd. If there is an error the mail that must still go is
written to a "still to go log".... that way users get an immediate return...
etc.
I use this methodology.... if the mail server is down... it will go as soon
as it comes back... and users never bitch at you ;)
Last thing is that if you do get the hell-in with the framework... using
JavaMail directly, really isnt that much code...
Good luck...
----- Original Message -----
From: "Raymond Holguin" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <users@tomcat.apache.org>
Sent: Monday, May 07, 2007 10:51 PM
Subject: Re: Tomcat randomly cannot connect to SMTP host
Dear all,
Yes you have all given me great advice and I appreciate it. Like I
mentioned this is a random issue that occurs, and currently it is working
fine. So when it goes down again I will try out some of your suggestions.
As for the code its a basic spring bean setup for the mailer
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host"><value>smtp.xxx.xxx</value></property>
</bean>
Then in my java code I have a service class that I call whenever I want to
send a message
private void sendMsg(String subject, String msgString, String[] toMail,
String fromMail, String[] ccMail) throws FRSException {
try {
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo(toMail) {
if ( ccMail != null) {
msg.setCc(ccMail);
}
msg.setSubject(subject);
msg.setFrom(fromMail);
msg.setSentDate(Calendar.getInstance().getTime());
msg.setText(new String(msgString));
mailSender.send(msg);
} catch (MailException me) {
logger.error(me);
throw new FRSException(me.getMessage());
}
}
Fargusson.Alan wrote:
I see you got a number of good suggestions. If you still have this
problem you could try doing a netstat command to see if your server is
holding the connections to the SMTP server. I have seen this type of
thing cause some weird problems.
If your server is holding several connections to the SMTP server it would
mean that the application isn't closing the socket when it is done.
-----Original Message-----
From: Raymond Holguin [mailto:[EMAIL PROTECTED]
Sent: Friday, May 04, 2007 12:38 PM
To: users@tomcat.apache.org
Subject: Tomcat randomly cannot connect to SMTP host
Hello,
I have tomcat 5.0.28 running on my Linux machine, and all my
applications running under this tomcat experience the same problem at the
same time which is why I believe it to be a tomcat issue.
When my applications attempt to send out an email I get this error
message
(Mail server connection failed; nested exception is
javax.mail.MessagingException: Could not connect to SMTP host: xxxxxx,
port: 25; nested exception is: java.net.ConnectException: Connection
refused)
The SMTP server is fine, because I can use it from other applications not
on that tomcat server. I can also telnet into the SMTP server just fine
from that same machine, so i don't believe its a server/port blocking
issue on the OS or hardware level. The only way I am able to resolve the
problem is to restart Tomcat. Once Tomcat is restarted, then all
operation with emailing works fine again. I cannot seem to force the
issue to happen so i don't know how reproduce it on demand, even though I
know that would help in solving the issue. This problem just seems to
come up randomly and wont go away until I restart tomcat.
If anyone can please help me solve this issue that would be greatly
appreciated. I have important applications running on this machine and
its a great inconvenience to those using the applications when this
problem comes up.
Thank you
-Ray
--
------------------------------------------------------------------------
Raymond Holguin
Programmer Analyst
College of Humanities, Arts, and Social Sciences
Tel: (951) 827-6212
Email: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]