Re: Javamail exception in tomcat 7.0.11

2012-06-19 Thread Kiran Badi

On 6/19/2012 11:23 AM, Tim Watts wrote:

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);

Looks like your mail session isn't getting initialized properly and you
left out that piece of the puzzle.  How  where does 'this.session' get
set?


This was the real issue.Caught the exception now and could see the root 
cause now and fixed it.Eureka you guys are genius and eye  for detail.


One more suggestion I need, I had mail.jar/mailapi.jar/pop3.jar/smtp.jar 
all over, they were in project library, tomcat lib and I remove all 
those reference and had just mail.jar in tomcat lib,bounced the server 
many times and only after that I managed to make this work.


How do you remove safely all reference without impacting the server or 
your build script ? Do you just comment out the reference of jars or 
your physically remove them from the folder ?
Now a days quite often my build fails if I remove or other jars,so want 
to learn this trick as well.



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



Re: Javamail exception in tomcat 7.0.11

2012-06-19 Thread Pid *
On 19 Jun 2012, at 06:24, Kiran Badi ki...@poonam.org wrote:

 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);

Unfortunately you've completely omitted the code for setting the
session object, so we can only guess why it's not working.


p


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=
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-namemail/mysitemailsession/res-ref-name
 res-typejavax.mail.Session/res-type
 res-authContainer/res-auth
 res-sharing-scopeShareable/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 

Re: Javamail exception in tomcat 7.0.11

2012-06-19 Thread Kiran Badi

On 6/19/2012 9:55 PM, Pid * wrote:

Unfortunately you've completely omitted the code for setting the
session object, so we can only guess why it's not working.
Yup Pid, I realized it later on when Tim highlighted it.Its fixed 
now.Thanks I am able to send mail comfortably.


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



Re: Javamail exception in tomcat 7.0.11

2012-06-19 Thread Mark Eggers
- Original Message -

 From: Kiran Badi ki...@poonam.org
 To: users@tomcat.apache.org
 Cc: 
 Sent: Tuesday, June 19, 2012 7:40 AM
 Subject: Re: Javamail exception in tomcat 7.0.11
 
 On 6/19/2012 11:23 AM, Tim Watts wrote:
  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);
  Looks like your mail session isn't getting initialized properly and you
  left out that piece of the puzzle.  How  where does 
 'this.session' get
  set?
 
 
 This was the real issue.Caught the exception now and could see the root cause 
 now and fixed it.Eureka you guys are genius and eye  for detail.
 
 One more suggestion I need, I had mail.jar/mailapi.jar/pop3.jar/smtp.jar all 
 over, they were in project library, tomcat lib and I remove all those 
 reference 
 and had just mail.jar in tomcat lib,bounced the server many times and only 
 after 
 that I managed to make this work.
 
 How do you remove safely all reference without impacting the server or your 
 build script ? Do you just comment out the reference of jars or your 
 physically 
 remove them from the folder ?
 Now a days quite often my build fails if I remove or other jars,so want to 
 learn 
 this trick as well.


If I remember correctly, you're using NetBeans. There are at least two ways of 
removing the JAR from the packaging without impacting your project.

If you're using the NetBeans standard build mechanism:

1. Go to Project-Properties-Libraries
2. Uncheck the 'Package' checkbox next to the JAR that should not be included

If you're using Maven with NetBeans:

1. Go into pom.xml
2. Add a scopeprovided/scope to each dependency that is provided

Note that if you associate a Tomcat server with your project on your 
development system and that Tomcat server has the JAR files, they should 
already show up in your build path. I've not extensively tested this, but just 
looking at a project they seem to be there (for me, some JDBC drivers).

. . . . just my two cents.
/mde/

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



Re: Javamail exception in tomcat 7.0.11

2012-06-19 Thread Kiran Badi

On 6/19/2012 11:09 PM, Mark Eggers wrote:

If I remember correctly, you're using NetBeans. There are at least two ways of 
removing the JAR from the packaging without impacting your project.

If you're using the NetBeans standard build mechanism:

1. Go to Project-Properties-Libraries
2. Uncheck the 'Package' checkbox next to the JAR that should not be included
Yes Mark, done this as well,but still get reference error for those 
jars.There is no checkbox, you just add it and then remove it thats only 
2 options I see.


I will fix this sometime later as now I am ignoring those errors as I no 
longer need those jars.


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



Javamail exception in tomcat 7.0.11

2012-06-18 Thread Kiran Badi

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=
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-namemail/mysitemailsession/res-ref-name
res-typejavax.mail.Session/res-type
res-authContainer/res-auth
res-sharing-scopeShareable/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)
   

Re: Javamail exception in tomcat 7.0.11

2012-06-18 Thread Tim Watts
On Tue, 2012-06-19 at 10:54 +0530, Kiran Badi wrote:
 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);

Looks like your mail session isn't getting initialized properly and you
left out that piece of the puzzle.  How  where does 'this.session' get
set?


  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=
  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-namemail/mysitemailsession/res-ref-name

Doesn't match your Resource definition name.

--tim

 res-typejavax.mail.Session/res-type
 res-authContainer/res-auth
 res-sharing-scopeShareable/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: