tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kiran Badi <ki...@poonam.org>
Subject Javamail exception in tomcat 7.0.11
Date Tue, 19 Jun 2012 05:24:22 GMT
Hi All,

I have send mail servlet, which looks something like below,

protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
        String emailRecipient = request.getParameter("name");
     //   String emailRecipient = "xxx";
         try {
             Message msg = new MimeMessage(this.session);
             msg.setFrom(new InternetAddress("xxx"));
             System.out.println(" remoteAddr is " + emailRecipient + "'");
             for (int i = 0; i < 10; i++) {
                 msg.setRecipients(Message.RecipientType.TO, 
InternetAddress.parse(emailRecipient, false));
             }

             msg.setSubject("Test email");
             msg.setText("Hello This is test mail");
             msg.setSentDate(new Date());
             Transport.send(msg); *(This is line number 60)*
             System.out.println("Message sent OK.");
         } catch (Exception ex) {
              
Logger.getLogger(MailSendingServlet.class.getName()).log(Level.SEVERE, 
null, ex);
         }
     }
}

and I have javamail reference declared in context.xml something like 
this one,

<Resource name="mail/ourstorymailsession"
                     auth="Container"
                     type="javax.mail.Session"
                     mail.smtp.host="smtp.gmail.com"
                     mail.smtp.port="465"
                     mail.smtp.auth="true"
                     mail.smtp.user="sender userid"
                     password="xxxx"
                     mail.smtp.starttls.enable="true"
                     
mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
                     mail.debug="true" />

and web.xml something like
<resource-ref>
<description>
    My site mail server
</description>
<res-ref-name>mail/mysitemailsession</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

With this setting now I am getting below exception,

avax.mail.MessagingException: Could not connect to SMTP host: localhost, 
port: 25;
   nested exception is:
     java.net.ConnectException: Connection refused: connect
     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
     at 
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
     at javax.mail.Service.connect(Service.java:295)
     at javax.mail.Service.connect(Service.java:176)
     at javax.mail.Service.connect(Service.java:125)
     at javax.mail.Transport.send0(Transport.java:194)
     at javax.mail.Transport.send(Transport.java:124)
     at indianads.MailSendingServlet.doPost(MailSendingServlet.java:60)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
     at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
     at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
     at 
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
     at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
     at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
     at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
     at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
     at 
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
     at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
     at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
     at 
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
     at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
     at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
     at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
     at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
     at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
     at 
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
     at 
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
     at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
     at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.ConnectException: Connection refused: connect
     at java.net.PlainSocketImpl.socketConnect(Native Method)
     at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
     at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
     at java.net.Socket.connect(Socket.java:529)
     at java.net.Socket.connect(Socket.java:478)
     at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
     at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
     ... 29 more

Now my problem is Where do I change the port setting and why is the 
servlet looking at port 25.I thought it should read config stuff from 
context.xml and should connect to smtp server mentioned in context.xml ? 
I checked all files of examples in both 7.0.11 and 7.0.27. I did not 
find mailservlet  nor could find entry of localhost in any context.xml 
?Below is link i referrred to troubleshoot this one ?

http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JavaMail_Sessions

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message