5-Oct-04 (Created: 5-Oct-04) | More in 'Howto'

How to send a jsp page as email under aspire

Consider submitting the following request to Aspire Serverside


http://host/update?request_name=sendMail&arg1=10&arg2=15

This request has the following arguments


request name
arg1
arg2

Request name is pointing to a request called sendMail. In your case it could be a more involved request where sendMail is just a portion of the over all request.


#
# Start the request with a pipeline
# If there is database activity, use the database pipeline part
# If There are updates involved you can use the query_type is update part
#
request.sendmail.classname=com.ai.db.DBPreTranslateArgsMultiRequestExecutor
request.sendmail.db=(your-db-alias)
request.sendmail.query_type=update

# Start the pipeline
request.sendmail.request.1=DoSomeStatusUpdateInTheDatabase
request.sendmail.request.2=GetFromToSubject
request.sendmail.request.3=GetBodyText
request.sendmail.request.4=FinalSendMail

# Responding after the pipeline
request.sendmail.redirectURL=(some url to go to after success)
request.sendmail.failureRedirectURL=(if something goes wrong)

#
#Expected inputs
#from, to, subject, bodyText
#
request.FinalSendMail.classname=com.ai.aspire.utils.MailRequestExecutor
request.FinalSendMail.smtpMailHost=smtp.btitelecom.net
request.FinalSendMail.user=sorry
request.FinalSendMail.password=sorry

#
# USing the URLStringReader to retrieve a url as a string
#
request.GetBodyText.classname=com.ai.parts.URLStringReaderPart
request.GetBodyText.URL=/{aspireContext}/display?url=MyJSPURL&arg1={arg1}&arg2={arg2}
request.GetBodyText.resultName=bodyText


#
# One possible way to get the from, to, and subject fields
# Or you could pass them from your input request directly
#
request.GetFromToSubject.classname=com.ai.db.DBRequestExecutor2
request.GetFromToSubject.db=(your-database)
request.GetFromToSubject.stmt=(Some select statement that can give the above value)

Let us see how the MyJSPURL is defined

This is no different from any other JSP definition.


MyJSPURL=/path/mypage.jsp
MyJSPURL.transformType=jsp
MyJSPURL.transfrom.classname=com.ai.jsp.JSPTransform
MyJSPURL.dataRequestName=MyJSPData

request.MyJSPData.classname=com.ai.htmlgen.DBHashTableFormHandler1

This definition is based on build 21. If you have a jsp page that is defined for earlier builds, that should work as well.

Additional needed jar files

To run the mail software you need two additional jar files placed in the web-inf/lib directory. These jar file are

1. Mail 113 jar

2. Activation 101 jar file

Builds

You need Build 21.x. The URLStringReaderPart is available only from this build

References

1. How to s'end emails on the server side using Aspire This example shows two additional things. One is to translate arguments if needed. The second is to use an asynchrnous part to delegate the email to a separate thread. This allows for faster responses.

2. Source code of the URLStringReaderPart

3. If you are migrating from build 20 to 21, please read this note on a change to the login variable

4. Build 21 release notes