You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by felix <fe...@crucial-systems.com> on 2001/11/13 22:14:08 UTC

UnknownHostException thrown from SmtpClient


Migrating some old code that uses the sun SmtpClient to a new server.

the SmtpClient throws an UnknownHostException, I'm using the i.p. address of
the mail server, which is actually on the same box.

i tried 127.0.0.1 and localhost and the named host (but not yet dns
transferred).

all the same exception.  the mailserver (exim) is not even being contacted.

i'm thinking its tomcat or jvm not knowing a dns host yet ?

clues anyone ?

I found one person relating the same thing:

they moved stuff from one tomcat(nt) to tomcat(linux) using the same smtp
server and it no longer worked. couldn't find the server.


thanks!




--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: UnknownHostException thrown from SmtpClient

Posted by Kevin Barnes <kb...@iamx.com>.
Tomcat 4 comes with the necessary jar files (mail.jar and activation.jar) for
using javamail in the common\lib directory. If you download the javamail 1.2
API from Sun it comes with many examples of how to use it in it's demo
directory.

-kb

Martin van den Bemt wrote:

> I like the idea of a queue which holds the mails and tries until it works
> (didn't have time to do that myself, just catching everything and not
> throwing any exceptions, just logging to a mail log file if it doesn't
> succeed).
> So it depends on your time you can invest in it I guess..
> I read somewhere that tomcat 4 has build in support for javamail and offers
> services to send mail via javamail. I think searching on javamail on the
> online backups of mailinglist backup might turn up some info. (eg
> http://marc.theaimsgroup.com/?l=tomcat-user&r=1&w=2)
>
> Have fun remodeling ;))
>
> Mvgr,
> Martin
>
> > -----Original Message-----
> > From: felix [mailto:felix@crucial-systems.com]
> > Sent: Tuesday, November 13, 2001 10:43 PM
> > To: Tomcat Users List
> > Subject: Re: UnknownHostException thrown from SmtpClient
> >
> >
> >
> > Thanks, I think that's what needs to be done anyway.
> >
> > on a related topic,
> > I've been trying to figure out if JavaMail threads / forks when it sends.
> >
> > Or if its worth writing an Emailer (implements Runnable) that would just
> > take care of its business and let tomcat go on its merrry way.
> >
> > the user doesn't need to know what we are emailing or if it succeeds.
> >
> > anybody have any thoughts on that ?  extra thread overhead ? waste of my
> > time ?
> >
> >
> > > From: "Martin van den Bemt" <ma...@isallineed.org>
> > > Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
> > > Date: Tue, 13 Nov 2001 22:21:23 +0100
> > > To: "Tomcat Users List" <to...@jakarta.apache.org>
> > > Subject: RE: UnknownHostException thrown from SmtpClient
> > >
> > > Use JavaMail instead.. The SmtpClient (at least if that is the one in
> > > com.sun or sun.) is as far as I know not even supported..
> > > Never had any problems with that, unless the jvm couldn't find
> > a host in the
> > > first place, it tends to never find it again.
> > >
> > > Mvgr,
> > > Martin
> >
> >
> > --
> > To unsubscribe:   <ma...@jakarta.apache.org>
> > For additional commands: <ma...@jakarta.apache.org>
> > Troubles with the list: <ma...@jakarta.apache.org>
> >
> >
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: UnknownHostException thrown from SmtpClient

Posted by Martin van den Bemt <ma...@isallineed.org>.
See below..

> On Tue, 13 Nov 2001, Martin van den Bemt wrote:
>
> > Date: Tue, 13 Nov 2001 22:49:12 +0100
> > From: Martin van den Bemt <ma...@isallineed.org>
> > Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> > To: Tomcat Users List <to...@jakarta.apache.org>
> > Subject: RE: UnknownHostException thrown from SmtpClient
> >
> > I like the idea of a queue which holds the mails and tries
> until it works
> > (didn't have time to do that myself, just catching everything and not
> > throwing any exceptions, just logging to a mail log file if it doesn't
> > succeed).
>
> That's exactly what your local SMTP server (sendmail or whatever) does for
> you.  Why reinvent the wheel?
>

Sendmail is good at bouncing mails, and we need to know about that. Since
the return address is always someone external to our company (and don't even
know about) we need to handle bounces and retry again (sending it directly
btw). If after some time the mail still bounces, we need to be informed and
take appropiate action (which sendmail or qmail cannot handle, or I don't
like them to handle that..).

Mvgr,
Martin


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: UnknownHostException thrown from SmtpClient

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 13 Nov 2001, Martin van den Bemt wrote:

> Date: Tue, 13 Nov 2001 22:49:12 +0100
> From: Martin van den Bemt <ma...@isallineed.org>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: RE: UnknownHostException thrown from SmtpClient
>
> I like the idea of a queue which holds the mails and tries until it works
> (didn't have time to do that myself, just catching everything and not
> throwing any exceptions, just logging to a mail log file if it doesn't
> succeed).

That's exactly what your local SMTP server (sendmail or whatever) does for
you.  Why reinvent the wheel?

> So it depends on your time you can invest in it I guess..
> I read somewhere that tomcat 4 has build in support for javamail and offers
> services to send mail via javamail. I think searching on javamail on the
> online backups of mailinglist backup might turn up some info. (eg
> http://marc.theaimsgroup.com/?l=tomcat-user&r=1&w=2)
>

See my previous response for a pointer to the Tomcat 4 docs about this.

> Have fun remodeling ;))
>
> Mvgr,
> Martin
>

Craig


>
> > -----Original Message-----
> > From: felix [mailto:felix@crucial-systems.com]
> > Sent: Tuesday, November 13, 2001 10:43 PM
> > To: Tomcat Users List
> > Subject: Re: UnknownHostException thrown from SmtpClient
> >
> >
> >
> > Thanks, I think that's what needs to be done anyway.
> >
> > on a related topic,
> > I've been trying to figure out if JavaMail threads / forks when it sends.
> >
> > Or if its worth writing an Emailer (implements Runnable) that would just
> > take care of its business and let tomcat go on its merrry way.
> >
> > the user doesn't need to know what we are emailing or if it succeeds.
> >
> > anybody have any thoughts on that ?  extra thread overhead ? waste of my
> > time ?
> >
> >
> > > From: "Martin van den Bemt" <ma...@isallineed.org>
> > > Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
> > > Date: Tue, 13 Nov 2001 22:21:23 +0100
> > > To: "Tomcat Users List" <to...@jakarta.apache.org>
> > > Subject: RE: UnknownHostException thrown from SmtpClient
> > >
> > > Use JavaMail instead.. The SmtpClient (at least if that is the one in
> > > com.sun or sun.) is as far as I know not even supported..
> > > Never had any problems with that, unless the jvm couldn't find
> > a host in the
> > > first place, it tends to never find it again.
> > >
> > > Mvgr,
> > > Martin
> >
> >
> > --
> > To unsubscribe:   <ma...@jakarta.apache.org>
> > For additional commands: <ma...@jakarta.apache.org>
> > Troubles with the list: <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: UnknownHostException thrown from SmtpClient

Posted by Martin van den Bemt <ma...@isallineed.org>.
I like the idea of a queue which holds the mails and tries until it works
(didn't have time to do that myself, just catching everything and not
throwing any exceptions, just logging to a mail log file if it doesn't
succeed).
So it depends on your time you can invest in it I guess..
I read somewhere that tomcat 4 has build in support for javamail and offers
services to send mail via javamail. I think searching on javamail on the
online backups of mailinglist backup might turn up some info. (eg
http://marc.theaimsgroup.com/?l=tomcat-user&r=1&w=2)

Have fun remodeling ;))

Mvgr,
Martin


> -----Original Message-----
> From: felix [mailto:felix@crucial-systems.com]
> Sent: Tuesday, November 13, 2001 10:43 PM
> To: Tomcat Users List
> Subject: Re: UnknownHostException thrown from SmtpClient
>
>
>
> Thanks, I think that's what needs to be done anyway.
>
> on a related topic,
> I've been trying to figure out if JavaMail threads / forks when it sends.
>
> Or if its worth writing an Emailer (implements Runnable) that would just
> take care of its business and let tomcat go on its merrry way.
>
> the user doesn't need to know what we are emailing or if it succeeds.
>
> anybody have any thoughts on that ?  extra thread overhead ? waste of my
> time ?
>
>
> > From: "Martin van den Bemt" <ma...@isallineed.org>
> > Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
> > Date: Tue, 13 Nov 2001 22:21:23 +0100
> > To: "Tomcat Users List" <to...@jakarta.apache.org>
> > Subject: RE: UnknownHostException thrown from SmtpClient
> >
> > Use JavaMail instead.. The SmtpClient (at least if that is the one in
> > com.sun or sun.) is as far as I know not even supported..
> > Never had any problems with that, unless the jvm couldn't find
> a host in the
> > first place, it tends to never find it again.
> >
> > Mvgr,
> > Martin
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: UnknownHostException thrown from SmtpClient

Posted by felix <fe...@crucial-systems.com>.

Using JavaMail now (tedious download process, can't just wget )

and i get a more descriptive exception:


javax.servlet.ServletException: Sending failed;
  nested exception is:
        javax.mail.MessagingException: 501 syntactically invalid HELO
argument(s)


So here is a good example for all of us why sun.net.smtp.SmtpClient should
be avoided.
it threw an UnknownHostException when the problem is completely different.

This is going to exim, not sendmail.




> 
>> From: "Martin van den Bemt" <ma...@isallineed.org>

>> Use JavaMail instead.. The SmtpClient (at least if that is the one in
>> com.sun or sun.) is as far as I know not even supported..
>> Never had any problems with that, unless the jvm couldn't find a host in the
>> first place, it tends to never find it again.
>> 
>> Mvgr,
>> Martin
> 
> 
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
> 
> 
> 


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: UnknownHostException thrown from SmtpClient

Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Tue, 13 Nov 2001, felix wrote:

> [snip]
>
> i have exim (http://www.exim.org) installed (it came with our dedicated
> server).  it appears to be more robust in terms of queuing, freezing,
> unfreezing, managing and retrying than classic sendmail.
>
> with xwindows you can open a manager to sort through the queue.
>
>
> of course i'm still getting this
>
> javax.servlet.ServletException: Sending failed;
>   nested exception is:
>         javax.mail.MessagingException: 501 syntactically invalid HELO
> argument(s)
>
> though it should be an exact replacement.
>
> code is dirt simple:
>
>         String FromAddress = "support@royalsweeps.com";
>         String ToAddress = "design@crucial-systems.com";
>         String Subject = "testttjavamail";
>         String Body = " bodydddyyy";
>
>         Properties p = System.getProperties();
>         p.put("mail.host","209.41.200.16");
>
>         MimeMessage message = new MimeMessage(Session.getInstance(p, null));
>         message.setFrom(new InternetAddress(FromAddress));
>         message.setRecipients(Message.RecipientType.TO,
>         InternetAddress.parse(ToAddress));
>         message.setSubject(Subject);
>         message.setText(Body);
>
>         Transport.send(message);
>

This sounds like a good question for the JavaMail interest mailing list,
once you verify that it happens to you in a stand-alone Java application
as well.  Since it's a javax.mail.MessagingException, it's not coming from
Tomcat directly.

You should be able to find a pointer to the mailing list on the JavaMail
page at java.sun.com.

Craig


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: UnknownHostException thrown from SmtpClient

Posted by felix <fe...@crucial-systems.com>.

> From: "Craig R. McClanahan" <cr...@apache.org>
>> on a related topic,
>> I've been trying to figure out if JavaMail threads / forks when it sends.

> Besides the fact that it's probably an insignificant effect on response
> time (unless you're sending large numbers of messages on one request),

that's what i wanted to hear. thanks!  its just a quick email send (to
another company), i just want to make the whole response as quick as
possible.

> By the way, Tomcat 4 offers support for a JavaMail resource that you can
> access from all of the servlets and JSP pages in your web app, without
> having to configure all of them for the appropriate SMTP host.  See
> Craig

bravo!  i was just thinking "why isn't javamail included if we should
definitely use it?"


on the other topic:

i have exim (http://www.exim.org) installed (it came with our dedicated
server).  it appears to be more robust in terms of queuing, freezing,
unfreezing, managing and retrying than classic sendmail.

with xwindows you can open a manager to sort through the queue.


of course i'm still getting this

javax.servlet.ServletException: Sending failed;
  nested exception is:
        javax.mail.MessagingException: 501 syntactically invalid HELO
argument(s)

though it should be an exact replacement.

code is dirt simple:

        String FromAddress = "support@royalsweeps.com";
        String ToAddress = "design@crucial-systems.com";
        String Subject = "testttjavamail";
        String Body = " bodydddyyy";

        Properties p = System.getProperties();
        p.put("mail.host","209.41.200.16");

        MimeMessage message = new MimeMessage(Session.getInstance(p, null));
        message.setFrom(new InternetAddress(FromAddress));
        message.setRecipients(Message.RecipientType.TO,
        InternetAddress.parse(ToAddress));
        message.setSubject(Subject);
        message.setText(Body);

        Transport.send(message);



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: UnknownHostException thrown from SmtpClient

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 13 Nov 2001, felix wrote:

> Date: Tue, 13 Nov 2001 16:43:02 -0500
> From: felix <fe...@crucial-systems.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@jakarta.apache.org>
> Subject: Re: UnknownHostException thrown from SmtpClient
>
>
> Thanks, I think that's what needs to be done anyway.
>
> on a related topic,
> I've been trying to figure out if JavaMail threads / forks when it sends.
>

The standard implementation of SMTP sending does not.  You could certainly
write one that does.  (In one of my past lives, I wrote a JavaMail
"Transport" implementation that interfaced to a fax broadcast service, and
the calling application could be configured to use multiple threads -- it
mattered when we were sending thousands of faxes for a for-pay
subscription service.)

> Or if its worth writing an Emailer (implements Runnable) that would just
> take care of its business and let tomcat go on its merrry way.
>
> the user doesn't need to know what we are emailing or if it succeeds.
>
> anybody have any thoughts on that ?  extra thread overhead ? waste of my
> time ?
>

Besides the fact that it's probably an insignificant effect on response
time (unless you're sending large numbers of messages on one request),
using a separate thread here can be ***very*** dangerous if your thread
that creates the response needs access to the original request.  Once the
service() method of your servlet returns, it is not legal to reference the
request attributes -- so, if your message sending thread took longer than
the rest of the service() method, you'd be out of luck.

By the way, Tomcat 4 offers support for a JavaMail resource that you can
access from all of the servlets and JSP pages in your web app, without
having to configure all of them for the appropriate SMTP host.  See

  http://jakarta.apache.org/tomcat/tomcat-4.0-doc/jndi-resources-howto.html

and read the section on "JavaMail Sessions" for configuration information
and a simple example.

Craig


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: UnknownHostException thrown from SmtpClient

Posted by felix <fe...@crucial-systems.com>.
Thanks, I think that's what needs to be done anyway.

on a related topic,
I've been trying to figure out if JavaMail threads / forks when it sends.

Or if its worth writing an Emailer (implements Runnable) that would just
take care of its business and let tomcat go on its merrry way.

the user doesn't need to know what we are emailing or if it succeeds.

anybody have any thoughts on that ?  extra thread overhead ? waste of my
time ?


> From: "Martin van den Bemt" <ma...@isallineed.org>
> Reply-To: "Tomcat Users List" <to...@jakarta.apache.org>
> Date: Tue, 13 Nov 2001 22:21:23 +0100
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Subject: RE: UnknownHostException thrown from SmtpClient
> 
> Use JavaMail instead.. The SmtpClient (at least if that is the one in
> com.sun or sun.) is as far as I know not even supported..
> Never had any problems with that, unless the jvm couldn't find a host in the
> first place, it tends to never find it again.
> 
> Mvgr,
> Martin


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: UnknownHostException thrown from SmtpClient

Posted by Martin van den Bemt <ma...@isallineed.org>.
Use JavaMail instead.. The SmtpClient (at least if that is the one in
com.sun or sun.) is as far as I know not even supported..
Never had any problems with that, unless the jvm couldn't find a host in the
first place, it tends to never find it again.

Mvgr,
Martin

> -----Original Message-----
> From: felix [mailto:felix@crucial-systems.com]
> Sent: Tuesday, November 13, 2001 10:14 PM
> To: Tomcat Users List
> Subject: UnknownHostException thrown from SmtpClient
>
>
>
>
> Migrating some old code that uses the sun SmtpClient to a new server.
>
> the SmtpClient throws an UnknownHostException, I'm using the i.p.
> address of
> the mail server, which is actually on the same box.
>
> i tried 127.0.0.1 and localhost and the named host (but not yet dns
> transferred).
>
> all the same exception.  the mailserver (exim) is not even being
> contacted.
>
> i'm thinking its tomcat or jvm not knowing a dns host yet ?
>
> clues anyone ?
>
> I found one person relating the same thing:
>
> they moved stuff from one tomcat(nt) to tomcat(linux) using the same smtp
> server and it no longer worked. couldn't find the server.
>
>
> thanks!
>
>
>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: UnknownHostException thrown from SmtpClient

Posted by felix <fe...@crucial-systems.com>.
btw. i can open a socket (port 25) directly via i.p.


> From: felix <fe...@crucial-systems.com>
> 
> 
> 
> Migrating some old code that uses the sun SmtpClient to a new server.
> 
> the SmtpClient throws an UnknownHostException, I'm using the i.p. address of
> the mail server, which is actually on the same box.
> 
> i tried 127.0.0.1 and localhost and the named host (but not yet dns
> transferred).
> 
> all the same exception.  the mailserver (exim) is not even being contacted.
> 
> i'm thinking its tomcat or jvm not knowing a dns host yet ?

since its not using dns anyway (i.p.), i don't know why sun SmtpClient would
throw an unknown host.

> 
> clues anyone ?
> 
> I found one person relating the same thing:
> 
> they moved stuff from one tomcat(nt) to tomcat(linux) using the same smtp
> server and it no longer worked. couldn't find the server.
> 
> 
> thanks!
> 
> 


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>