javamail: method blocks instead of throwing exception
Julien Martin
Ranch Hand
Joined: Apr 24, 2004
Posts: 383
posted
0
Hello,
I have the following code in a Swing/Spring application:
When the email address I try and send the message to is erroneous i.e. julien@domain or julien@domainDoesNotExist.com the above method blocks indefinitely without throwing any exception...
I'm afraid this is not exactly what I meant. Please try the following:
1. Sending your mails has to happen in its own Thread.
2. In case your mail sending thread has successfully send the mail, you set a variable back in your main thread.
3. In your main thread you set a timer or something that realizes how many time has been spent.
4. After your time limit has been reached, you could check whether the mail sending thread set that variable yet (see 2.). If not, stop that thread and you could go on in your main thread.
BTW: Are you sure, that the mail connection you use to send that email, has no timeout parameter that can be set?
Cheers,
Ramon
Julien Martin
Ranch Hand
Joined: Apr 24, 2004
Posts: 383
posted
0
Good point Ramon.
First: I dropped the thread implementation: it now execute sequentially.
Second: upon your advice, I added this to my javamailsender bean:
a value of 1000 would mean timeout after 1 second.
Can you ensure that the properties you've set are known to your mail session at runtime?
There should be a Session.getProperties() method and/or Session.getProperty("mail.smtp.connectiontimeout") method.
If not set, mail.smtp.connectiontimeout and mail.smtp.timeout are both infinite and that's the behaviour your code shows ...
Cheers,
Ramon
Julien Martin
Ranch Hand
Joined: Apr 24, 2004
Posts: 383
posted
0
I checked that my JavaMailSenderImpl does have a getJavaMailProperties method and also that the values are in the mailSender's session.
and
However, it does seem those properties are ignored...
Regards,
Julien.
If you're trying to debug JavaMail, one of the recommended things to try is turning on debug mode, so you can see the conversation between your code and the server.
However you seem to be trying to debug JavaMail and Spring at the same time. I recommend putting Spring aside and debugging JavaMail by itself to start with, otherwise you don't know whether you are debugging JavaMail or Spring.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: javamail: method blocks instead of throwing exception