Solved

Mail API & Retrying Host

Posted on 2002-06-18
5
167 Views
Last Modified: 2012-05-04
I have a working app that send mail successfully when the mail server is ok (obvious so far!).

What I want to be able to do is detect that the host is not available and retry with a second host.

I'd like to be able to detect this before sending a message, such as in the code:

Session session = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(session);

Where props contains the host name.

I know that the host could fail at any point after this, and during the sending of a particular message.

It would be good to be able to catch an exception (MessagingException?) at the point of making the host connection, and if it fails, try another host. It would be even better to be able to detect the failed host connection during sending each message and retry with another host, but I think that is more difficult, given the connection has already been made.

Any ideas?
Thanks
0
Comment
Question by:harrywillis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Accepted Solution

by:
Venci75 earned 100 total points
ID: 7087659
you can try something like this:

try {
  Session session = Session.getInstance(props, null);
  session.getStore("imap").connect(host,username,password);
} catch (MessagingException e) {
  // you will be here if 'connect' has failed
}
0
 

Author Comment

by:harrywillis
ID: 7087752
Thanks. I want something more like:

try {
  Session session = Session.getInstance(props, null);
  session.getStore("imap").connect(host,username,password);
} catch (MessagingException e) {
  // try connection to 2nd host
}

Or even better, when sending a message and the host cannot be contacted, to retry with another host.
0
 
LVL 1

Expert Comment

by:rahul_ashish
ID: 7134736
well if Session.getInstance() fails then session will be null. u can check for the null condition and use a While loop to connect to other host. this ways u need only one try and catch and u will be saved form nested try and catch. when connection is sucessful u can break out of while loop.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8860469
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this
question is:

- points to Venci75

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question