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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]