[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tomcat-user
Subject:    Re: Tomcat 6 and javamail
From:       Don Millhofer <dmillhofer () netscape ! com>
Date:       2008-11-27 16:46:33
Message-ID: 7.0.1.0.2.20081127113741.05af2548 () netscape ! com
[Download RAW message or body]


Hi Lyallex, for everybody that is still struggling with this issue, here is a base \
non-authentication email class.  Once you get this working start adding the special \
features you need.   This worked with my hosting provider (Kattare) who were \
absolutely worthless in providing any guidance, after much testing.

import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class Email{
    String  d_email, d_password, d_host, d_port;
    
    public Email(String email, String password, String host, String port) {
        d_email = email;
        d_password = password;
        d_host = host;
        d_port  = port;
    }
    
    public boolean send(String m_to, String m_subject, String m_text) {
        // email address
        String to = m_to;
        String from = d_email;
        //  ISP mail server
        String host = d_host;
        // 
        Properties props = new Properties();
        // static transport.send() - need to specify which host to send it to
        props.put("mail.smtp.host", host);
        // To see what is going on
        props.put("mail.debug", "false");
        //
        Session session = Session.getInstance(props);
        try {
            // message
            Message msg = new MimeMessage(session);
            //message attributes
            msg.setFrom(new InternetAddress(from));
            InternetAddress[] address = {new InternetAddress(to)};
            msg.setRecipients(Message.RecipientType.TO, address);
            msg.setSubject(m_subject);
            msg.setSentDate(new Date());
            // message content
            msg.setText(m_text);        
            //send
            Transport.send(msg);
            return true;
        }
        catch (MessagingException mex) {
            // 
            mex.printStackTrace();
            return false;
        }
    }
 }
 
Happy holidays

Don


At 09:15 AM 11/27/2008, you wrote:
> 2008/11/27 Rainer Frey <frey@inxmail.de>:
> > On Thursday 27 November 2008 12:52:56 Lyallex wrote:
> > 
> > 
> > (It would be easier to answer if you'd stop top quoting - but I won't correct
> > this whole mail)
> 
> Well that's most kind of you, you are being very patient.
> 
> I think I need to take a step back here. The boss is happy that
> sending email from within the application is now working. I on the
> other hand want to know why something that works in Tomcat 5 doesn't
> work in Tomcat 6. He's less than inclined to pay for that information
> however :-(
> 
> Anyway, I will certainly do some more testing, maybe install a clean
> Tomcat 6 and create a simple web app that just sends email to a
> preconfigured address ... whatever, I'll post results here including
> code, mail debug and anything else that might help
> 
> Thanks again for your time
> 
> lyallex
> 
> > 
> > > OK, firstly thanks for the feedback so far
> > > 
> > > Let me be quite clear about one thing.
> > > I am using the same mail server in both cases. Tomcat and Eclipse are
> > > running on the same physical device with the same IP address.
> > > The mail server does not require authentication when accessed from the
> > > office subnet. The server guys have confirmed this.
> > 
> > So the problem is certainly on Java side.
> > 
> > > If I configure a JavaMail session as described in the following resource
> > > 
> > > http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
> > > (JavaMail section)
> > > 
> > > and set auth to false in context.xml everything works perfectly when
> > > sending mail from the web application.
> > 
> > It then should not be anything related to Javamail or Java version,
> > incompatible jar files ...
> > 
> > > I am using the same mail server for the standalone test, the test
> > > where the mail component is configured to use the JNDI resource
> > > configured in context.xml and the test where the mail component uses
> > > the same configuration mechanism as the standlone test. The only test
> > > that fails is the last one.
> > > 
> > > Something has changed since Tomcat 5.  I have exactly the same
> > > component running in several webapps on Tomcat 5 servers without any
> > > need to configure JNDI resources/Mail sessions etc
> > 
> > In such a setup, a javamail session is no managed resource for tomcat. I can't
> > imagine how the tomcat version could have any influence on that. There must
> > be any other difference between your eclipse runtime and this failing tomcat.
> > 
> > > JAVA_OPTS and CATALINA_OPTS have not been modified by me and do not
> > > contain anything other that the default settings (none of which appear
> > > to have anything to do with mail config settings).
> > 
> > Is there any other webapp that might set system properties with mail related
> > content? I'd make sure and use an empty Properties object for your test. the
> > only reason to use System.getProperties() is the ability to pass JavaMail
> > configuration to the JVM command line. I'm not sure what static variables and
> > Singletons Javamail has, so I'd test without the resource configuration (even
> > if you don't use it anyway) and the Javamail jars in WEB-INF/lib. If this is
> > not successful, I guess it's impossible to help unless you post more code,
> > complete exception messages and perhaps the output of Javamail with
> > mail.debug=true. As I think it is not directly related to tomcat, I'd
> > recommend asking on the Javamail list though, they might know more details.
> > 
> > Rainer
> > 
> > > 
> > > Any ideas much appreciated.
> > > 
> > > lyallex
> > > 
> > > 2008/11/26 Rainer Frey <frey@inxmail.de>:
> > > > On Wednesday 26 November 2008 08:37:14 Rainer Frey wrote:
> > > > > > In the MailServer constructor I do the following
> > > > > > 
> > > > > > properties = System.getProperties();
> > > > > > ...
> > > > > > properties.put("mail.smtp.auth", "false");
> > > > > > 
> > > > > > so it looks like a different properties bundle is being used when I
> > > > > > run this in Tomcat ... does any of this make sense ??
> > > > 
> > > > Argh, I overlooked that you use System.getProperties() here. If you
> > > > specify any JavaMail related Properties in JAVA_OPTS or CATALINA_OPTS
> > > > environment variables, this will be different indeed. You might want to
> > > > check your tomcat start script.
> > > > 
> > > > Rainer
> > > > 
> > > > 
> > > > ---------------------------------------------------------------------
> > > > To start a new topic, e-mail: users@tomcat.apache.org
> > > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > > For additional commands, e-mail: users-help@tomcat.apache.org
> > > 
> > > ---------------------------------------------------------------------
> > > To start a new topic, e-mail: users@tomcat.apache.org
> > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > 
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> > 
> > 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic