Hi there,
We have a number of sites that generate lots of error emails from integration. Many of them are false positives where the integration fails because of the data source is empty, or other scenarios where it's OK not to send out that email. In addition, I often have the need to customize the email subject to include the name of the server or domain used so I can distinguish between different environments without having to always specify that in the Subject field (which often gets forgotten when we restore a staging environment from a backup of production).
To solve both scenarios, I would love to have a cancellable notification subscriber that fires on the email being sent for integration (from the BatchIntegrationScheduledTaskAddIn for example), Here's a sample implementation I would love to be able to write:
[Subscribe(Integration.OnBeforeSendingEmail)] public class HandleIntegrationErrors : NotificationSubscriber { public override void OnNotify(string notification, NotificationArgs ) { var myArgs = (OnBeforeSendingEmailArgs)args; bool shouldCancel; switch(myArgs.MessageType) { case MessageType.Success: if (SomeCondition(myArgs.IntegrationJob)) { shouldCancel = true; } break; case MessageType.Warning: case MessageType.Error: if (SomeOtherCondition(myArgs.Message)) { shouldCancel = true; } break; } if (shouldCancel) { myArgs.Cancel = shouldCancel; } else { myArgs.Email.Subject += $" - on {System.Environment.MachineName}"; } } }
OnBeforeSendingEmailArgs would exposes a few items:
- The email (A MailMessage) being sent
- MessageType - The job outcome from the MessageType enum
- The Message
- The name of the scheduled task
- A reference to the integration job that raised this error
- A Cancel property
When Cancel is true, the email shouldn't be sent.
Does this make sense and sound like a reasonable request?
Thanks!
Imar