You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark Whitby <ug...@cs.bham.ac.uk> on 2006/03/11 16:54:58 UTC

Re: Problems with JavaMail - catching bounced emails - help

Actually I do have one further problem.  Is there any way that the program 
can catch emails that bounce back because the to address is invalid?  At the 
moment they just come into my inbox but I want it so that they cause an 
error in my code e.g Mail delivery failed: returning message to sender.  If 
the address is invalid e.g test@hotmailcom I want an Java exception to catch 
this rather than just get a bounced email.

Is there any way to do this?

Mark

----- Original Message ----- 
From: "Mark Whitby" <ug...@cs.bham.ac.uk>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Saturday, March 11, 2006 3:43 PM
Subject: Re: Problems with JavaMail


> Len,
>
> Thanks very much for your help, my class is now working fine.  Ironically 
> enough my smtp server is localhost as I use an ssh client to connect to my 
> Universities mailhost via the ssh connection and then my emails go via 
> that.
>
> Mark
>
> ----- Original Message ----- 
> From: "Len Popp" <le...@gmail.com>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Saturday, March 11, 2006 3:32 PM
> Subject: Re: Problems with JavaMail
>
>
> You need to look at the SMTP server settings in Outlook Express and
> use the same settings in your JavaMail config. The mail.smtp.host for
> example shouldn't be "localhost", it should be whatever email server
> Outlook Express uses (look in Tools > Accounts).
> --
> Len
>
> On 3/11/06, Mark Whitby <ug...@cs.bham.ac.uk> wrote:
>> Thanks for the email Len,
>>
>> So if that's the case where am I going wrong with my code to get the 
>> error
>> described in my first email?  What settings do I need to change in my
>> current configuration to get my code to work?
>>
>> Many thanks
>>
>> Mark
>>
>> ----- Original Message -----
>> From: "Len Popp" <le...@gmail.com>
>> To: "Tomcat Users List" <us...@tomcat.apache.org>
>> Sent: Saturday, March 11, 2006 3:15 PM
>> Subject: Re: Problems with JavaMail
>>
>>
>> Yes, you need an SMTP server. If you've got Outlook Express running,
>> you can use the same server it's using.
>> --
>> Len
>>
>> On 3/11/06, Mark Whitby <ug...@cs.bham.ac.uk> wrote:
>> > Dear all,
>> >
>> > I'm currently getting the following error when trying to test the 
>> > JavaMail
>> > set up: javax.mail.MessagingException: Could not connect to SMTP host:
>> > localhost, port: 25; nested exception is: java.net.ConnectException:
>> > Connection refused: connect
>> >
>> > I'm using Tomcat 5.5 and have installed the jar files correctly as 
>> > stated
>> > here: http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html
>> >
>> > I'm guessing that there's a problem with my SMTP settings.  However,
>> > (apologise if I sound dense here) but the only mail client I have on my 
>> > PC
>> > is Outlook Express.  Am I right in saying then that as well as JavaMail
>> > that I need an smtp server?  If so where can I get one?  If not where 
>> > am I
>> > going wrong?
>> >
>> > I have the following setups in my files:
>> >
>> > context.xml:
>> >
>> > <Context>
>> >
>> >  <ResourceLink name="jdbc/TestDB"
>> >   type="javax.sql.DataSource"
>> >      global="jdbc/TestDB"/>
>> >
>> > <ResourceLink name="mail/Session" auth="Container"
>> >             type="javax.mail.Session"
>> >             mail.smtp.host="localhost"/>
>> >
>> > </Context>
>> >
>> > web.xml:
>> >
>> > <resource-ref>
>> >   <description>JavaMail Connection</description>
>> >   <res-ref-name>mail/Session</res-ref-name>
>> >   <res-type>javax.mail.Session</res-type>
>> >   <res-auth>Container</res-auth>
>> > </resource-ref>
>> >
>> > Finally this is the code i'm testing:
>> >
>> > Context initCtx = new InitialContext();
>> >             Context envCtx = (Context) initCtx.lookup("java:comp/env");
>> >             Session session = (Session) envCtx.lookup("mail/Session");
>> >
>> >             Message message = new MimeMessage(session);
>> >             message.setFrom(new 
>> > InternetAddress("ug82msw@cs.bham.ac.uk"));
>> >             InternetAddress to[] = new InternetAddress[1];
>> >             to[0] = new InternetAddress("ug82msw@cs.bham.ac.uk");
>> >             message.setRecipients(Message.RecipientType.TO, to);
>> >             message.setSubject("Test email");
>> >             message.setContent("Test email", "text/plain");
>> >             Transport.send(message);
>> >
>> > Can anyone tell me where I'm going wrong?
>> >
>> > Many thanks
>> >
>> > Mark Whitby
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with JavaMail - catching bounced emails - help

Posted by Len Popp <le...@gmail.com>.
You won't get a Java exception for that because email is delivered
asynchronously. The bounce message comes back long after your program
has sent the email. To catch these you'll need a program that monitors
the inbox and handles the bounce messages appropriately. I don't know
of such a program, but it wouldn't surprise me if you could find some
code somewhere.
--
Len

On 3/11/06, Mark Whitby <ug...@cs.bham.ac.uk> wrote:
> Actually I do have one further problem.  Is there any way that the program
> can catch emails that bounce back because the to address is invalid?  At the
> moment they just come into my inbox but I want it so that they cause an
> error in my code e.g Mail delivery failed: returning message to sender.  If
> the address is invalid e.g test@hotmailcom I want an Java exception to catch
> this rather than just get a bounced email.
>
> Is there any way to do this?
>
> Mark
>
> ----- Original Message -----
> From: "Mark Whitby" <ug...@cs.bham.ac.uk>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Saturday, March 11, 2006 3:43 PM
> Subject: Re: Problems with JavaMail
>
>
> > Len,
> >
> > Thanks very much for your help, my class is now working fine.  Ironically
> > enough my smtp server is localhost as I use an ssh client to connect to my
> > Universities mailhost via the ssh connection and then my emails go via
> > that.
> >
> > Mark
> >
> > ----- Original Message -----
> > From: "Len Popp" <le...@gmail.com>
> > To: "Tomcat Users List" <us...@tomcat.apache.org>
> > Sent: Saturday, March 11, 2006 3:32 PM
> > Subject: Re: Problems with JavaMail
> >
> >
> > You need to look at the SMTP server settings in Outlook Express and
> > use the same settings in your JavaMail config. The mail.smtp.host for
> > example shouldn't be "localhost", it should be whatever email server
> > Outlook Express uses (look in Tools > Accounts).
> > --
> > Len
> >
> > On 3/11/06, Mark Whitby <ug...@cs.bham.ac.uk> wrote:
> >> Thanks for the email Len,
> >>
> >> So if that's the case where am I going wrong with my code to get the
> >> error
> >> described in my first email?  What settings do I need to change in my
> >> current configuration to get my code to work?
> >>
> >> Many thanks
> >>
> >> Mark
> >>
> >> ----- Original Message -----
> >> From: "Len Popp" <le...@gmail.com>
> >> To: "Tomcat Users List" <us...@tomcat.apache.org>
> >> Sent: Saturday, March 11, 2006 3:15 PM
> >> Subject: Re: Problems with JavaMail
> >>
> >>
> >> Yes, you need an SMTP server. If you've got Outlook Express running,
> >> you can use the same server it's using.
> >> --
> >> Len
> >>
> >> On 3/11/06, Mark Whitby <ug...@cs.bham.ac.uk> wrote:
> >> > Dear all,
> >> >
> >> > I'm currently getting the following error when trying to test the
> >> > JavaMail
> >> > set up: javax.mail.MessagingException: Could not connect to SMTP host:
> >> > localhost, port: 25; nested exception is: java.net.ConnectException:
> >> > Connection refused: connect
> >> >
> >> > I'm using Tomcat 5.5 and have installed the jar files correctly as
> >> > stated
> >> > here: http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html
> >> >
> >> > I'm guessing that there's a problem with my SMTP settings.  However,
> >> > (apologise if I sound dense here) but the only mail client I have on my
> >> > PC
> >> > is Outlook Express.  Am I right in saying then that as well as JavaMail
> >> > that I need an smtp server?  If so where can I get one?  If not where
> >> > am I
> >> > going wrong?
> >> >
> >> > I have the following setups in my files:
> >> >
> >> > context.xml:
> >> >
> >> > <Context>
> >> >
> >> >  <ResourceLink name="jdbc/TestDB"
> >> >   type="javax.sql.DataSource"
> >> >      global="jdbc/TestDB"/>
> >> >
> >> > <ResourceLink name="mail/Session" auth="Container"
> >> >             type="javax.mail.Session"
> >> >             mail.smtp.host="localhost"/>
> >> >
> >> > </Context>
> >> >
> >> > web.xml:
> >> >
> >> > <resource-ref>
> >> >   <description>JavaMail Connection</description>
> >> >   <res-ref-name>mail/Session</res-ref-name>
> >> >   <res-type>javax.mail.Session</res-type>
> >> >   <res-auth>Container</res-auth>
> >> > </resource-ref>
> >> >
> >> > Finally this is the code i'm testing:
> >> >
> >> > Context initCtx = new InitialContext();
> >> >             Context envCtx = (Context) initCtx.lookup("java:comp/env");
> >> >             Session session = (Session) envCtx.lookup("mail/Session");
> >> >
> >> >             Message message = new MimeMessage(session);
> >> >             message.setFrom(new
> >> > InternetAddress("ug82msw@cs.bham.ac.uk"));
> >> >             InternetAddress to[] = new InternetAddress[1];
> >> >             to[0] = new InternetAddress("ug82msw@cs.bham.ac.uk");
> >> >             message.setRecipients(Message.RecipientType.TO, to);
> >> >             message.setSubject("Test email");
> >> >             message.setContent("Test email", "text/plain");
> >> >             Transport.send(message);
> >> >
> >> > Can anyone tell me where I'm going wrong?
> >> >
> >> > Many thanks
> >> >
> >> > Mark Whitby
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org