Developer forum

Forum » Feature requests » Cancellable subscriber for email notifications

Cancellable subscriber for email notifications

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

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


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Imar,
That seems to be a good suggestion and it will be implemented at some time.
I was thinking to work around this with the current Data Integration JobFinished notification subscriber and the EmailHandler "BeforeSending" email subscriber.
So it is possible to check and then cache the job error in the JobFinished notification and then in the EmailHandler "BeforeSending" subscriber you can "somehow"
check if this email should be sent or no. Can this suit to fix your problems?
Regards, Dmitrij

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Cool, thanks; I'll give that a try....