MailerMDBpublic class MailerMDB extends Object implements javax.ejb.MessageDrivenBean, javax.jms.MessageListener
Methods Summary |
---|
public void | ejbCreate()
| public void | ejbRemove()
| public void | onMessage(javax.jms.Message recvMsg)This method expect a javax.jms.ObjectMessage that
contains a {@link Email} as the message object
try
{
Debug.print( "MailerMDB.onMessage(" + recvMsg + ")" );
ObjectMessage msg = ( ObjectMessage ) recvMsg;
Email email = ( Email ) msg.getObject( );
send( email.getTo( ), email.getSubject( ), email.getBody( ) );
}
catch ( Exception e )
{
Debug.print( "Unable to send the email", e );
}
| public void | send(java.lang.String to, java.lang.String subject, java.lang.String body)
Debug.print( "MailerMDB.send(" + to + "," + subject + ",...)" );
InitialContext ic = new InitialContext( );
Session session = ( Session ) ic.lookup( JNDINames.MAIL_SESSION );
javax.mail.Message msg = new MimeMessage( session );
msg.setFrom( );
msg.setRecipients( javax.mail.Message.RecipientType.TO, InternetAddress.parse( to, false ) );
msg.setSubject( subject );
msg.setDataHandler( new DataHandler( body, "text/html" ) );
msg.setHeader( "X-Mailer", "JavaMailer" );
msg.setSentDate( new Date( ) );
Transport.send( msg );
| public void | setMessageDrivenContext(javax.ejb.MessageDrivenContext mdc)
|
|