users@glassfish.java.net

Re: sending email from withing application deployed into Glassfish

From: <glassfish_at_javadesktop.org>
Date: Tue, 04 Dec 2007 13:33:46 PST

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