users@glassfish.java.net

Re: sending email from withing application deployed into Glassfish

From: Gabe Wong <gabrielw_at_ngasi.com>
Date: Tue, 04 Dec 2007 13:53:16 -0800

glassfish_at_javadesktop.org wrote:
> No, not readily.
>
> JavaMail doesn't have a transaction API, and I don't know of a transactional Mail server.
>
> What you CAN do, tho, is perhaps use JMS as your mail mechanism. Then you can rely on JMS's reliable message handling to deliver the message.
>
> The JMS request is part of your overall transaction (so it get commited/rolledback with the rest of them as appropriate), but once committed, you have a listener feeding JavaMail with all of the appropriate error checks etc. When the SMTP server finally accepts the message, you're done (as it's now the SMTP server responsibility). But the key is that you consider "sending an email" to be posting to a reliable, transactional JMS queue with full knowledge that since JMS is reliable, that message will (eventually) get sent to an SMTP server.
> [Message sent by forum member 'whartung' (whartung)]
>
> http://forums.java.net/jive/thread.jspa?messageID=248506
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>

If the complete hand off to the SMTP server is considered a transaction,
then you may place the code in a try block. If no exception is thrown,
then the transaction is completed. Note well that SMTP is a store and
forward protocol. That is after a successful hand off to the SMTP server,
it is placed in a queue to be delivered to the receiver's SMTP server.
The receiver's SMTP server may or may not accept the message. etc.
Or the message may end up in the user's junk box.


-- 
Regards
Gabe Wong
NGASI AppServer Manager
Application server installation and configuration AUTOMATION
http://www.ngasi.com