You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Edward Elhauge <ee...@uncanny.net> on 2006/06/14 01:37:40 UTC

Failure on sending email using Flow.

Hi, I have a problem that is stumping me. I've created a class
to send canned email messages; it uses the Sun mail.jar,
Debian Linux, Cocoon 2.1.8, and the Jetty AppServer.

I can use this class in a stand alone mode and get mail sent out (this
is true whether I'm running as myself or as the cocoon user).

When I try to use the same class within Flow I get nothing at all.
There isn't even an error in the log. The status is always "SENT"
so it doesn't seem like an exception is every thrown.

Here is how I invoke the class within Flow:
    var sendMailObj = new SendConfirmMail() ;
    var sendResult  = sendMailObj.sendCanned() ;

Here is the stand alone test that works perfectly.

======= CocoonMailTest.java =======
import javax.mail.* ;
import javax.mail.internet.* ;

import com.roche.rms.bioinfo.SendConfirmMail ;

public class CocoonMailTest {

  public static void main(String args [])
  {
    System.out.println("START") ;

    SendConfirmMail sendMailObj   = new SendConfirmMail() ;

    String result = sendMailObj.sendCanned() ;

    System.out.println("result " + sendMailStatus) ;

    System.out.println("END") ;
  } 
   
}     
======= END =======

I've included the class I wrote at the bottom.

My best guess is that there is something missing in the environment
of Cocoon, that my user environment has. Perhaps in the Session Object?

Anybody have any ideas on how to debug this?

======= SendConfirmMail.java =======

package com.roche.rms.bioinfo ;

import java.util.Properties ;

import javax.mail.Session ;
import javax.mail.Message ;
import javax.mail.MessagingException ;
import javax.mail.Transport ;

import javax.mail.internet.MimeMessage ;
import javax.mail.internet.InternetAddress ;
import javax.mail.internet.AddressException ;

public class SendConfirmMail {

  private final static String smtpHost    = "127.0.0.1" ;
  private final static String smtpPort    = "25" ;

  private String _statusMsg               = "UNINIT" ;

  public SendConfirmMail() {
    _statusMsg                    = "NEW" ;
  }

  public String getStatus() {
    return _statusMsg ;
  }

  public String sendCanned() {
    String from                   = "elhaugee" ;
    String to                     = "edward.elhauge@roche.com" ;
    String subject                = "Canned Message from Cocoon 1" ;
    String msgBody                = "Body of Canned Message 1" ;

    return sendMail(from, to, subject, msgBody) ;
  }

  public String sendMail(String from, String to, String subject, String msgBody)
  {
    // Create a mail session
    Properties properties         = new Properties() ;
    properties.put("mail.smtp.host", smtpHost) ;
    properties.put("mail.smtp.port", smtpPort) ;

    // Session session               = Session.getInstance(properties);
    Session session               = Session.getDefaultInstance(properties, null);

    // Construct the message
    MimeMessage msg               = new MimeMessage(session) ;

    _statusMsg                    = "READY" ;

    try {
      msg.setFrom(new InternetAddress(from)) ;
    } catch ( MessagingException e ) {
      _statusMsg                  = "FAIL setFrom: " + e ;
      return _statusMsg ;
    }

    try {
      msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)) ;
    } catch ( MessagingException e ) {
      _statusMsg                  = "FAIL setRecipient: " + e ;
      return _statusMsg ;
    }

    try {
      msg.setSubject(subject) ;
    } catch ( MessagingException e ) {
      _statusMsg                  = "FAIL setSubject: " + e ;
      return _statusMsg ;
    }

    try {
      msg.setContent(msgBody, "text/html; charset=UTF-8") ;
    } catch ( MessagingException e ) {
      _statusMsg                  = "FAIL setContent: " + e ;
      return _statusMsg ;
    }

    // Send the message
    try {
      msg.saveChanges() ;
    } catch ( MessagingException e ) {
      _statusMsg                  = "FAIL saveChanges: " + e ;
      return _statusMsg ;
    }

    // Send the message
    try {
      Transport trans             = session.getTransport("smtp");
      trans.send(msg) ;
    } catch ( MessagingException e ) {
      _statusMsg                  = "FAIL Transport.send: " + e ;
      return _statusMsg ;
    }

    _statusMsg                    = "SENT" ;
    return _statusMsg ;
  }

}
======= END =======

-- 
        Edward Elhauge <ee...@uncanny.net>
"Colourless green ideas sleep furiously." -- Noam Chomsky

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Failure on sending email using Flow.

Posted by Jason Johnston <ja...@Intrado.com>.
Sorry folks, sent to the wrong list. :(


On Wed, 2006-06-21 at 15:24 -0600, Jason Johnston wrote:
> > Thanks Jason the geronimo-spec jars were the problems. More below.
> >
> > * Jason Johnston <co...@lojjic.net> wrote on [2006-06-13 17:11]:
> >> Edward Elhauge wrote:
> >> >Hi, I have a problem that is stumping me. I've created a class
> >> >to send canned email messages; it uses the Sun mail.jar,
> >> >Debian Linux, Cocoon 2.1.8, and the Jetty AppServer.
> >> >
> >> >I can use this class in a stand alone mode and get mail sent out (this
> >> >is true whether I'm running as myself or as the cocoon user).
> >> >
> >> >When I try to use the same class within Flow I get nothing at all.
> >> >There isn't even an error in the log. The status is always "SENT"
> >> >so it doesn't seem like an exception is every thrown.
> >>
> >> When you run your Java test class, I assume it is run outside the Cocoon
> >> environment, correct?  My first guess would be a classpath issue.
> >>
> >> Make sure that the Sun mail.jar and activation.jar are in Cocoon's
> >> WEB-INF/lib, and that the geronimo-spec-* version of both are *not*
> >> there, as they will conflict.
> >
> > Yes I did have the Sun jars, but I had to get rid of the geronimo-spec
> > ones also. The mail doesn't go through if you use the geronimo-spec jars
> > alone. I guess geronimo-spec is not totally compliant with the Sun Spec,
> > or is plain broken?
> >
> > To be able to rebuild and reinstall the release you need to exclude
> > the mail block, otherwise the geronimo-spec jars come back. To bad there
> > isn't an easy way to provide equivalent jars to fulfill dependencies.
> 
> 
> Good to know that was the issue.
> 
> FYI, the Cocoon trunk code has been converted to use Maven for its build
> process and dependency resolution; one advantage of this is that Maven is
> able to download the Sun JARs directly from an official location at build
> time.  The Cocoon distribution no longer has to include the geronimo JARs
> simply to satisfy compile-time dependencies (they could not redistribute
> the Sun JARs due to license restrictions.)  So in future versions this
> will "just work".
> 
> 
> 

Re: Failure on sending email using Flow.

Posted by Jason Johnston <co...@lojjic.net>.
> Thanks Jason the geronimo-spec jars were the problems. More below.
>
> * Jason Johnston <co...@lojjic.net> wrote on [2006-06-13 17:11]:
>> Edward Elhauge wrote:
>> >Hi, I have a problem that is stumping me. I've created a class
>> >to send canned email messages; it uses the Sun mail.jar,
>> >Debian Linux, Cocoon 2.1.8, and the Jetty AppServer.
>> >
>> >I can use this class in a stand alone mode and get mail sent out (this
>> >is true whether I'm running as myself or as the cocoon user).
>> >
>> >When I try to use the same class within Flow I get nothing at all.
>> >There isn't even an error in the log. The status is always "SENT"
>> >so it doesn't seem like an exception is every thrown.
>>
>> When you run your Java test class, I assume it is run outside the Cocoon
>> environment, correct?  My first guess would be a classpath issue.
>>
>> Make sure that the Sun mail.jar and activation.jar are in Cocoon's
>> WEB-INF/lib, and that the geronimo-spec-* version of both are *not*
>> there, as they will conflict.
>
> Yes I did have the Sun jars, but I had to get rid of the geronimo-spec
> ones also. The mail doesn't go through if you use the geronimo-spec jars
> alone. I guess geronimo-spec is not totally compliant with the Sun Spec,
> or is plain broken?
>
> To be able to rebuild and reinstall the release you need to exclude
> the mail block, otherwise the geronimo-spec jars come back. To bad there
> isn't an easy way to provide equivalent jars to fulfill dependencies.


Good to know that was the issue.

FYI, the Cocoon trunk code has been converted to use Maven for its build
process and dependency resolution; one advantage of this is that Maven is
able to download the Sun JARs directly from an official location at build
time.  The Cocoon distribution no longer has to include the geronimo JARs
simply to satisfy compile-time dependencies (they could not redistribute
the Sun JARs due to license restrictions.)  So in future versions this
will "just work".




Re: Failure on sending email using Flow.

Posted by Jason Johnston <co...@lojjic.net>.
> Thanks Jason the geronimo-spec jars were the problems. More below.
>
> * Jason Johnston <co...@lojjic.net> wrote on [2006-06-13 17:11]:
>> Edward Elhauge wrote:
>> >Hi, I have a problem that is stumping me. I've created a class
>> >to send canned email messages; it uses the Sun mail.jar,
>> >Debian Linux, Cocoon 2.1.8, and the Jetty AppServer.
>> >
>> >I can use this class in a stand alone mode and get mail sent out (this
>> >is true whether I'm running as myself or as the cocoon user).
>> >
>> >When I try to use the same class within Flow I get nothing at all.
>> >There isn't even an error in the log. The status is always "SENT"
>> >so it doesn't seem like an exception is every thrown.
>>
>> When you run your Java test class, I assume it is run outside the Cocoon
>> environment, correct?  My first guess would be a classpath issue.
>>
>> Make sure that the Sun mail.jar and activation.jar are in Cocoon's
>> WEB-INF/lib, and that the geronimo-spec-* version of both are *not*
>> there, as they will conflict.
>
> Yes I did have the Sun jars, but I had to get rid of the geronimo-spec
> ones also. The mail doesn't go through if you use the geronimo-spec jars
> alone. I guess geronimo-spec is not totally compliant with the Sun Spec,
> or is plain broken?
>
> To be able to rebuild and reinstall the release you need to exclude
> the mail block, otherwise the geronimo-spec jars come back. To bad there
> isn't an easy way to provide equivalent jars to fulfill dependencies.


Good to know that was the issue.

FYI, the Cocoon trunk code has been converted to use Maven for its build
process and dependency resolution; one advantage of this is that Maven is
able to download the Sun JARs directly from an official location at build
time.  The Cocoon distribution no longer has to include the geronimo JARs
simply to satisfy compile-time dependencies (they could not redistribute
the Sun JARs due to license restrictions.)  So in future versions this
will "just work".


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Failure on sending email using Flow.

Posted by Edward Elhauge <ee...@uncanny.net>.
Thanks Jason the geronimo-spec jars were the problems. More below.

* Jason Johnston <co...@lojjic.net> wrote on [2006-06-13 17:11]:
> Edward Elhauge wrote:
> >Hi, I have a problem that is stumping me. I've created a class
> >to send canned email messages; it uses the Sun mail.jar,
> >Debian Linux, Cocoon 2.1.8, and the Jetty AppServer.
> >
> >I can use this class in a stand alone mode and get mail sent out (this
> >is true whether I'm running as myself or as the cocoon user).
> >
> >When I try to use the same class within Flow I get nothing at all.
> >There isn't even an error in the log. The status is always "SENT"
> >so it doesn't seem like an exception is every thrown.
> 
> When you run your Java test class, I assume it is run outside the Cocoon 
> environment, correct?  My first guess would be a classpath issue.
> 
> Make sure that the Sun mail.jar and activation.jar are in Cocoon's 
> WEB-INF/lib, and that the geronimo-spec-* version of both are *not* 
> there, as they will conflict.

Yes I did have the Sun jars, but I had to get rid of the geronimo-spec
ones also. The mail doesn't go through if you use the geronimo-spec jars
alone. I guess geronimo-spec is not totally compliant with the Sun Spec,
or is plain broken?

To be able to rebuild and reinstall the release you need to exclude
the mail block, otherwise the geronimo-spec jars come back. To bad there
isn't an easy way to provide equivalent jars to fulfill dependencies.

Anyway, I have my app happily sending HTML email confirmations from
Cocoon Forms now.

Cheers,

Ed Elhauge

-- 
        Edward Elhauge <ee...@uncanny.net>
"Colourless green ideas sleep furiously." -- Noam Chomsky

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Failure on sending email using Flow.

Posted by Jason Johnston <co...@lojjic.net>.
Edward Elhauge wrote:
> Hi, I have a problem that is stumping me. I've created a class
> to send canned email messages; it uses the Sun mail.jar,
> Debian Linux, Cocoon 2.1.8, and the Jetty AppServer.
> 
> I can use this class in a stand alone mode and get mail sent out (this
> is true whether I'm running as myself or as the cocoon user).
> 
> When I try to use the same class within Flow I get nothing at all.
> There isn't even an error in the log. The status is always "SENT"
> so it doesn't seem like an exception is every thrown.

When you run your Java test class, I assume it is run outside the Cocoon 
environment, correct?  My first guess would be a classpath issue.

Make sure that the Sun mail.jar and activation.jar are in Cocoon's 
WEB-INF/lib, and that the geronimo-spec-* version of both are *not* 
there, as they will conflict.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org