You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by todd thorner <tt...@lycos.com> on 2003/10/05 13:47:38 UTC

My Mail is Bombing

Struts Newbie Says Hi,

I have problems with the "Email" function of my Struts webapp (deployed for now on a local machine running Tomcat 4.1.24).

Maybe I just don't understand how JavaMail works with a smtp server?  I can use my machine to successfully telnet in to my ISP's smtp server on 25...


I have the following in my Tomcat deployment's server.xml file:

<ResourceParams name="mail/Session">
  <parameter>
    <name>mail.smtp.host</name>
    <value>smtp.myispmailserver.net</value> // USED FOR SUCCESSFUL TELNET
  </parameter>
</ResourceParams>


I have the following in my webapp's "web.xml" file:

<res-ref-name>
  mail/Session
</res-ref-name>
<res-type>
  javax.mail.Session
</res-type>
<res-auth>
  Container
</res-auth>


I have the following in my webapp's "struts-config.xml" file:

<form-beans>
  <form-bean name="sendMailForm"
    type="com.me.myactionforms.SendMailForm"/>
</form-beans>

<action
  path="/MessageSubmit"
  type="com.me.myactions.SendMailAction"
  name="sendMailForm"
  validate="true"
  input="/pages/SendMail.jsp">
  <forward
    name="success"
    path="/pages/ThankYou4_Message.html"/>
  <forward 
    name="fail"
    path="/pages/SendMessage_Failed.html"/>
</action>


I have the following in my "SendMail.jsp" file:

<html:form method="POST" action="/MessageSubmit"
  focus="message">
  <table>
    <tr>
      <th align="center" colspan="3">
        Enter your name, email address and the message to be sent
      </th>
    </tr>
    <tr>
      <th align="right">Email Address:</th>
      <td align="left" colspan="2">
        <html:text property="emailAddress" size="25"/>
      </td>
    </tr>
    <tr>
      <th align="right">To:</th>
      <td align="left" colspan="2">
        <html:text property="recipient" size="25"/>
      </td>
    </tr>
    <tr>
      <th align="right">Subject:</th>
      <td align="left" colspan="2">
        <html:text property="subject" size="25"/>
      </td>
    </tr>
    <tr>
      <th align="right" valign="top">Message:</th>
      <td colspan="3">
        <html:textarea property="message" rows="10" cols="60" value=""/>
      </td> 
    </tr>
  </table>
  <!-- PLUS RESET AND SUBMIT BUTTONS -->
</html:form>


I have the following in my "SendMailForm.java" file:

public class SendMailForm extends ActionForm {

  private String emailAddress = null;
  private String recipient = null;
  private String subject = null;
  private String message = null;

  // GETTERS/SETTERS OMITTED FROM THIS STRUTS-USER QUESTION

  // RESET() METHOD ALSO OMMITTED (SETS ALL PROPERTIES TO NULL)

  public ActionErrors validate( ActionMapping mapping, HttpServletRequest req ) {

    ActionErrors errors = new ActionErrors();
    setEmailAddress( req.getParameter( "emailAddress" ) );
    setRecipient( req.getParameter( "recipient" ) );
    setSubject( req.getParameter( "subject" ) );
    setMessage( req.getParameter( "message" ) );
    if( ( emailAddress == null ) || ( emailAddress.length() < 1 ) )
      errors.add( "emailAddress", new ActionError( "error.emailAddress.required" ) );
    if( ( message == null ) || ( message.length() < 1 ) )
      errors.add( "message", new ActionError( "error.message.required" ) );

    return errors;
  }
}


I have the following in my "SendMailAction.java" file:

public ActionForward execute( ActionMapping mapping, ActionForm form,  HttpServletRequest req,
                                HttpServletResponse resp ) throws Exception {

  boolean successfulTransport = false;
  String from = req.getParameter( "emailAddress" );
  String to = req.getParameter( "recipient" );
  String subject = req.getParameter( "subject" );
  String messageContent = req.getParameter( "message" );
  PrintWriter theWriter = resp.getWriter();
  resp.setContentType( "text/plain" );

  try {

    InitialContext initialContext = new InitialContext();
    Context environmentContext = ( Context )  initialContext.lookup( "java:comp/env" );
    Session theMailSession = ( Session )  environmentContext.lookup( "mail/Session" );

    // THE LINE BELOW IS THE POINT DURING RUNTIME EXECUTION WHEN THE WEBAPP APPEARS TO PUNK OUT

    MimeMessage theMessage = new MimeMessage( theMailSession );

    // THE LINE ABOVE IS THE POINT DURING RUNTIME EXECUTION WHEN THE WEBAPP APPEARS TO PUNK OUT

    theMessage.setFrom( new InternetAddress( from ) );
    InternetAddress destinationList[] = new InternetAddress[]
      { new InternetAddress( to ) };  
    theMessage.setRecipients( Message.RecipientType.TO , destinationList );
    theMessage.setSubject( subject );
    theMessage.setText( messageContent );

    Transport.send( theMessage );

    successfulTransport = true;
  } 
  catch ( Throwable exc ) {

    System.out.println( "Problem with SendMailAction.execute() try{} block" );

    theWriter.println( "EXCEPTION:  " + exc );
    theWriter.println( "<pre>" );
    exc.printStackTrace( theWriter );
    theWriter.println( "</pre>" );
  }

  if( ! successfulTransport )
    return( mapping.findForward( Constants.FAIL ) );
  else
    return( mapping.findForward( Constants.SUCCESS );
}


When the webapp punks out it sends me to the "SendMessage_Failed.html" page.
The stack trace says "NoClassDefFoundError: javax/activation/DataSource"
Calling theMailSession.getProperties().toString() during runtime returns: "{mail.transport.protocol=smtp, scope=Shareable, auth=Container, ..., mail.smtp.host=localhost}"


Anyone have any ideas?  Thanks for any solutions or guesses.



____________________________________________________________
Get advanced SPAM filtering on Webmail or POP Mail ... Get Lycos Mail!
http://login.mail.lycos.com/r/referral?aid=27005

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] My Mail is Bombing

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
This is totally OT but what on earth is this JAF thing? As an example 
Sun says:

"if a browser obtained a JPEG image, this framework would enable the 
browser to identify that stream of data as an JPEG image, and from that 
type, the browser could locate and instantiate an object that could 
manipulate, or view that image"

Well, that is not exactly explanatory. Browsers do that anyway, or at 
least all the major browsers out there today. So what are they on about? 
And how does something server-side affect the way the browser behaves 
client-side?

It's the most bizarre intro to a technology I've ever read.

Adam



On 10/05/2003 02:09 PM Yann Cébron wrote:
> Todd,
> 
> you need to add activation.jar to your webapp or TC (common/lib)
> 
> d/l:
> 
> http://java.sun.com/products/javabeans/glasgow/jaf.html
> 
> HTH,
>     Yann
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 

-- 
struts 1.1 + tomcat 5.0.12 + java 1.4.2
Linux 2.4.20 RH9


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: My Mail is Bombing

Posted by Yann C�bron <ya...@yahoo.de>.
Todd,

you need to add activation.jar to your webapp or TC (common/lib)

d/l:

http://java.sun.com/products/javabeans/glasgow/jaf.html

HTH,
    Yann




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org