cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edward Elhauge ...@uncanny.net>
Subject Failure on sending email using Flow.
Date Tue, 13 Jun 2006 23:37:40 GMT
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


Mime
View raw message