Sergey,

I think the following will work, not 100% sure, am just getting back to
using JavaMail after a 
3 year absence (I used the v1.0 in 1998 and haven't since)

Not clear where in your Servlet lifecycle you are creating the
javax.mail.Session.
If in the servlet init(), then you may have to get it out of there.

You are probably doing 

javax.mail.Session mailsession =
javax.mail.Session.getDefaultInstance(properties, null)

somewhere.

This initializes the mail session and everything else follows from here.
If the mail session is null, everything else (Message creation,
Transport.send(msg) ..) will fail.

You need to re instantiate the javax.mail.Session, AFTER you are sure
you have 
a valid connection to your ISP. So repeat the steps starting with 

javax.mail.Session mailsession = Session.getDefaultInstance(...) all the
way to Transport.send()

This should solve the problem.

If this is happening inside servlet init, you may need to get the code
out of there and
invoke it through some other mechanism as servlet init is invoked ONCE
at servlet lifecycle begin by the
servlet container.  Then the servlet will probablly stay in memory  and
init() will not be invoked every future servlet invocation. 

Alternatively, you may want to throw a ServletException inside init() if
your mail session is not initialized, then the servlet will not
be instantiated and the next time it is invoked ( hopefully there is a
connection to your ISP by this time) the servlet will instantiate the
mail session successfully and will itself be instantiated successfully
and all will be well.
If this is not clear send me the code and I may be able to help further.


Nitin Borwankar.


"Ushakov, Sergey N" wrote:
> 
> Hi,
> 
> sorry for probable (but I hope not 100% :) offtopic, but it is my last
> resort as I could not get response at jGuru and Sun forums. And I did not
> dare to ask at James developer's forum...
> 
> It's a programmer's question: how can one re-initialize JavaMail networking
> enviromnent just before sending mail?
> 
> I use JavaMail in a servlet with Tomcat, and everything works perfectly if
> my ISP connection was up when the servlet was launched. Otherwize
> Transport.send() fails with "javax.mail.MessagingException: Unknown SMTP
> host" at javax.mail.Transport.send0(Transport.java:219) - even when ISP
> connection is available. How can I make JavaMail "forgive the offense" that
> originates from its startup?
> 
> Regards,
> Sergey Ushakov
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to