3 Replies Latest reply on Jun 2, 2008 11:06 AM by pmuir

    Transaction safe mail sending

    avi

      Hi,


      Is there a way to send mail only when the current transaction commits?




      Right now I use renderer.render("...") but when the call returns the mail is already sent.


      Because I could not find a way for transaction safe mail sending, I tried the following will as the second best:



      1. when I call renderer.render not send the mail just render the Message and store it in the database

      2. an asynchronous method checks this table and sends mail



      But I am stuck because:



      1. I do not know how to replace the transport with my implementation

      2. how to find the original when I send the mails

      3. how to serialize/deserialize the Message



      I appreciate any help.

      Thanks,

      Viktor

        • 1. Re: Transaction safe mail sending
          leonardinius

          From forum search:



          • 2. Re: Transaction safe mail sending
            avi

            Thank you for your reply, but unfortunately I already found these posts and they are no help because:



            1. The first post where I read that I should change the transport. But there is simply not enough information in the post for me to actually make it happen. And I need some kind of dynamic way to change the active transport and in the post they say it comes from a configuration file.

            2. I don't really understand how the second post helps me. If I get it right it is about creating my own smtp server (or use a  third party one) to tunnel my emails. What you suggest is that I should send the mail to this local server, and write some flag to the database and the mail server should tunnel only those messages which have a flag in the database? (I think that this is a real overkill)

            • 3. Re: Transaction safe mail sending
              pmuir

              Raise a onTransactionCompletionEvent and render the mail from the @Observer - you may need trunk to get the email rendering to work quite right in this event.