You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Renato <re...@yahoo.com> on 2002/06/19 16:44:32 UTC

Problems with Catalina and mail.jar

Hi all,

I found a weird behaviour with mail.jar and Tomcat 4.0.4. Suppose the straightforward servlet:

import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class EmailServlet extends HttpServlet
{
    public void doPost (HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {   
        doGet(request, response);
    }
        
    public void doGet (HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {       
        String to = request.getParameter("to");
        String from = request.getParameter("from");
        String host = request.getParameter("host");

        Properties props = new Properties();
        props.put("mail.smtp.host", host);

        Session session = Session.getDefaultInstance(props, null);
         try
        {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject("Test");
            msg.setSentDate(new Date());

            Transport.send(msg);
         }
        catch (MessagingException mex)
        {
         mex.printStackTrace();

        }

    }

}

If I accidently type a wrong host for the first time in the URI, I'm not able to send e-mails anymore ( try a second time, with a right server ), since the it looks like the "mail.smtp.host" property stays "hardcoded" and I'm not able to overwrite it.

Since I have clients in a Virtual Host environment, I had to ask them to put a copy mail.jar in /lib directory, so they will not be affected by this. Anyway, once they set their "mail.smtp.host", they can't change anymore.

Anyone seem this ? Is this a Mail API feature ? 

Thanks

Renato - Brazil.                                       



---------------------------------
Do You Yahoo!?
Sign-up for Video Highlights of 2002 FIFA World Cup

Re: Problems with Catalina and mail.jar

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.
This doesn't have anything to do with Tomcat, it is the way you are
using the JavaMail API.  You need to use getInstance() instead of
getDefaultInstance().  getDefaultInstance() sets the properties
globally.

Renato wrote:
> 
> Hi all,
> 
> I found a weird behaviour with mail.jar and Tomcat 4.0.4. Suppose the straightforward servlet:
> 
> import java.util.*;
> import java.io.*;
> import javax.mail.*;
> import javax.mail.internet.*;
> import javax.activation.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> 
> public class EmailServlet extends HttpServlet
> {
>     public void doPost (HttpServletRequest request, HttpServletResponse response)
>         throws ServletException, IOException
>     {
>         doGet(request, response);
>     }
> 
>     public void doGet (HttpServletRequest request, HttpServletResponse response)
>         throws ServletException, IOException
>     {
>         String to = request.getParameter("to");
>         String from = request.getParameter("from");
>         String host = request.getParameter("host");
> 
>         Properties props = new Properties();
>         props.put("mail.smtp.host", host);
> 
>         Session session = Session.getDefaultInstance(props, null);
>          try
>         {
>             Message msg = new MimeMessage(session);
>             msg.setFrom(new InternetAddress(from));
>             InternetAddress[] address = {new InternetAddress(to)};
>             msg.setRecipients(Message.RecipientType.TO, address);
>             msg.setSubject("Test");
>             msg.setSentDate(new Date());
> 
>             Transport.send(msg);
>          }
>         catch (MessagingException mex)
>         {
>          mex.printStackTrace();
> 
>         }
> 
>     }
> 
> }
> 
> If I accidently type a wrong host for the first time in the URI, I'm not able to send e-mails anymore ( try a second time, with a right server ), since the it looks like the "mail.smtp.host" property stays "hardcoded" and I'm not able to overwrite it.
> 
> Since I have clients in a Virtual Host environment, I had to ask them to put a copy mail.jar in /lib directory, so they will not be affected by this. Anyway, once they set their "mail.smtp.host", they can't change anymore.
> 
> Anyone seem this ? Is this a Mail API feature ?
> 
> Thanks
> 
> Renato - Brazil.
> 
> ---------------------------------
> Do You Yahoo!?
> Sign-up for Video Highlights of 2002 FIFA World Cup

-- 
----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problems with Catalina and mail.jar

Posted by Renato <re...@yahoo.com>.
Silly me... :)). It worked perfectly !
Thanks !!
  Jun Inamori <ju...@oop-reserch.com> wrote: Hi,

I think this is not the bug of Tomcat.
Please try:
Session.getInstance
instead of:
Session.getDefaultInstance

On Jun19, 2002 07:44 -0700, Renato wrote:
> 
> Hi all,
> 
> I found a weird behaviour with mail.jar and Tomcat 4.0.4. Suppose the straightforward servlet:
> 
> import java.util.*;
> import java.io.*;
> import javax.mail.*;
> import javax.mail.internet.*;
> import javax.activation.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> 
> public class EmailServlet extends HttpServlet
> {
> public void doPost (HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException
> { 
> doGet(request, response);
> }
> 
> public void doGet (HttpServletRequest request, HttpServletResponse response)
> throws ServletException, IOException
> { 
> String to = request.getParameter("to");
> String from = request.getParameter("from");
> String host = request.getParameter("host");
> 
> Properties props = new Properties();
> props.put("mail.smtp.host", host);
> 
> Session session = Session.getDefaultInstance(props, null);
> try
> {
> Message msg = new MimeMessage(session);
> msg.setFrom(new InternetAddress(from));
> InternetAddress[] address = {new InternetAddress(to)};
> msg.setRecipients(Message.RecipientType.TO, address);
> msg.setSubject("Test");
> msg.setSentDate(new Date());
> 
> Transport.send(msg);
> }
> catch (MessagingException mex)
> {
> mex.printStackTrace();
> 
> }
> 
> }
> 
> }
> 
> If I accidently type a wrong host for the first time in the URI, I'm not able to send e-mails anymore ( try a second time, with a right server ), since the it looks like the "mail.smtp.host" property stays "hardcoded" and I'm not able to overwrite it.
> 
> Since I have clients in a Virtual Host environment, I had to ask them to put a copy mail.jar in /lib directory, so they will not be affected by this. Anyway, once they set their "mail.smtp.host", they can't change anymore.
> 
> Anyone seem this ? Is this a Mail API feature ? 
> 
> Thanks
> 
> Renato - Brazil. 
> 
> 
> 
> ---------------------------------
> Do You Yahoo!?
> Sign-up for Video Highlights of 2002 FIFA World Cup

Happy Java programming!
-----------------------------------
Jun Inamori
OOP-Reserch
E-mail: jun@oop-reserch.com
URL: http://www.oop-reserch.com/

--
To unsubscribe, e-mail: 
For additional commands, e-mail: 



---------------------------------
Do You Yahoo!?
Sign-up for Video Highlights of 2002 FIFA World Cup

Re: Problems with Catalina and mail.jar

Posted by Jun Inamori <ju...@oop-reserch.com>.
Hi,

I think this is not the bug of Tomcat.
Please try:
   Session.getInstance
instead of:
   Session.getDefaultInstance

On Jun19, 2002 07:44 -0700, Renato wrote:
> 
> Hi all,
> 
> I found a weird behaviour with mail.jar and Tomcat 4.0.4. Suppose the straightforward servlet:
> 
> import java.util.*;
> import java.io.*;
> import javax.mail.*;
> import javax.mail.internet.*;
> import javax.activation.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> 
> public class EmailServlet extends HttpServlet
> {
>     public void doPost (HttpServletRequest request, HttpServletResponse response)
>         throws ServletException, IOException
>     {   
>         doGet(request, response);
>     }
>         
>     public void doGet (HttpServletRequest request, HttpServletResponse response)
>         throws ServletException, IOException
>     {       
>         String to = request.getParameter("to");
>         String from = request.getParameter("from");
>         String host = request.getParameter("host");
> 
>         Properties props = new Properties();
>         props.put("mail.smtp.host", host);
> 
>         Session session = Session.getDefaultInstance(props, null);
>          try
>         {
>             Message msg = new MimeMessage(session);
>             msg.setFrom(new InternetAddress(from));
>             InternetAddress[] address = {new InternetAddress(to)};
>             msg.setRecipients(Message.RecipientType.TO, address);
>             msg.setSubject("Test");
>             msg.setSentDate(new Date());
> 
>             Transport.send(msg);
>          }
>         catch (MessagingException mex)
>         {
>          mex.printStackTrace();
> 
>         }
> 
>     }
> 
> }
> 
> If I accidently type a wrong host for the first time in the URI, I'm not able to send e-mails anymore ( try a second time, with a right server ), since the it looks like the "mail.smtp.host" property stays "hardcoded" and I'm not able to overwrite it.
> 
> Since I have clients in a Virtual Host environment, I had to ask them to put a copy mail.jar in /lib directory, so they will not be affected by this. Anyway, once they set their "mail.smtp.host", they can't change anymore.
> 
> Anyone seem this ? Is this a Mail API feature ? 
> 
> Thanks
> 
> Renato - Brazil.                                       
> 
> 
> 
> ---------------------------------
> Do You Yahoo!?
> Sign-up for Video Highlights of 2002 FIFA World Cup

Happy Java programming!
-----------------------------------
Jun Inamori
OOP-Reserch
E-mail: jun@oop-reserch.com
URL:    http://www.oop-reserch.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>