I have a custom event system handler that sends an email when a publish transaction fails. The event is registered like this:

this.EventSystem.Subscribe<PublishTransaction, SaveEventArgs>    
    (this.SendNotificationEmail, EventPhases.TransactionCommitted);

The SendNotificationEmail method looks like this:

private void SendNotificationEmail(PublishTransaction transaction, 
    SaveEventArgs args, EventPhases phases)
    if (transaction.Instruction.ResolveInstruction.Purpose == ResolvePurpose.Publish && 
        transaction.State == PublishTransactionState.Failed)
        // Send email

The issue I'm having is that the SendNotificationEmail method is called twice per publication transaction. This leads to multiple emails per failed transaction.

Any ideas why the event would be triggered more than once?

  • Are you publishing to multiple publishing targets? Commented Apr 22, 2015 at 17:30
  • When I publish to multiple targets, the event is triggered twice per target. Commented Apr 22, 2015 at 17:44

2 Answers 2


In general, the Save event is called for any save (change) of the PublishTransaction, not only for state changes. I'm not sure why a second save happens when the state is Failed (perhaps additional info is received from CD transport/deployment).

Anyways, your implementatiom should not rely on a single Save event, but detect the state change. You could do that by hooking into the Initiated phase of the save and, if the state is Failed, load another instance of the PublishTransaction to test if the state before the save event occurred was already Failed or not.

  • This makes sense. I was assuming (without any basis) that each event would only be called once per event phase. To solve my issue, I ended up caching each transaction id, and only sending the email the first time the event is triggered. Commented Apr 22, 2015 at 17:51

While publishing an item, each publishing target results in a transaction. In your code you are subscribing SendNotificationEmail method per transaction.

So If you publish to a multiple publishing targets, the "SendNotificationEmail" method will be called for each target(or transaction) and if it fails, the email will be send per target(or transaction) and will result in multiple emails.

  • I'm getting two emails per target, though. If I publish to one target, I get 2 emails; if I publish to two targets, I get 4 emails, etc. Commented Apr 22, 2015 at 17:42
  • If you publish to multiple targets, you will get multiple Publish Transactions (one per target). Commented Apr 22, 2015 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.