tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: help requested - javax.mail.SendFailedException: intermittently
Date Wed, 26 Jun 2002 14:59:43 GMT
Howdy,
It's a good idea to encapsulate the mail sending functionality in a
separate class, e.g. MyMailer, rather than in the servlet.  That mailer
would have a method like sendMessage(subject, from, to, contents),
setHost(), setPort(), and maybe also reset().  It would take care of
creating the Message, Session, talking to the Transport, etc.

I know the above doesn't answer your question ;)  But it's a good idea
anyways.  That way you could reset the mailer on error and try again.
Can you describe "intermittently" with more detail?  E.g. does it always
work the first time?  

By the way, why that no argument constructor in a servlet?

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Rob Cartier [mailto:rcartier@snet.net]
>Sent: Wednesday, June 26, 2002 10:53 AM
>To: tomcat-user@jakarta.apache.org
>Subject: help requested - javax.mail.SendFailedException:
intermittently
>
>I am running tomcat 4.0.2 and jdk 1.4  on RedHat 7.2
>and every so often  this peice of code
>
>import java.io.*;
>import java.util.*;
>import javax.mail.*;
>import javax.mail.internet.InternetAddress;
>import javax.mail.internet.MimeMessage;
>import javax.servlet.*;
>import javax.servlet.http.*;
>
>public class MailPremierApplication extends HttpServlet
>{
>
>    public MailPremierApplication()
>    {
>    }
>
>    public void doPost(HttpServletRequest request, HttpServletResponse
>response)
>        throws IOException, ServletException
>    {
>		....
>		....
>
>        PrintWriter writer = response.getWriter();
>        response.setContentType("text/html");
>        writer.println("<html>");
>        writer.println("<head>");
>        writer.println("<title>Mail Sending Results</title>");
>        writer.println("</head>");
>        writer.println("<body bgcolor=\"white\">");
>	try
>        {
>            Properties props = new Properties();
>            props.put("xxxxxx", "xxxxx.com");
>            Session mailConnection = Session.getInstance(props, null);
>            Message msg = new MimeMessage(mailConnection);
>            javax.mail.Address to_whom = new InternetAddress(to);
>            javax.mail.Address from_who = new InternetAddress(from);
>            msg.setContent(full_msg, "text/plain");
>            msg.setFrom(from_who);
>            msg.setRecipient(javax.mail.Message.RecipientType.TO,
to_whom);
>            msg.setSubject(subject);
>            Transport.send(msg);
>            writer.println("<strong>Message successfully
sent!</strong>");
>        }
>        catch(Throwable t)
>        {
>            writer.println("<font color=\"red\">");
>            writer.println("ENCOUNTERED EXCEPTION:  " + t);
>            writer.println("<pre>");
>            System.out.println("ENCOUNTERED EXCEPTION:  " + t);
>            t.printStackTrace(writer);
>            writer.println("</pre>");
>            writer.println("</font>");
>            writer.println("</body>");
>            writer.println("</html>");
>
>        }
>
>
>generates an error occasionally
>
>ENCOUNTERED EXCEPTION:  javax.mail.SendFailedException: Sending failed;
>  nested exception is:
>	javax.mail.MessagingException: Could not connect to SMTP host:
>xxxxxx.com,
>port: 25;
>  nested exception is:
>	java.net.ConnectException: Connection refused
>
>
>In order to fix this I need to restart tomcat and all is once again ok.
>
>Any and all ideas are welcome
>
>
>Robert Cartier
>112 Fieldbrook Rd
>Middletown, Ct. 06457-1746
>
>
>
>
>
>--
>To unsubscribe, e-mail:   <mailto:tomcat-user-
>unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:tomcat-user-
>help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message