Developer forum

Forum » CMS - Standard features » Prevent sending of Emails using Notifications

Prevent sending of Emails using Notifications

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have to implement some rules for preventing the send of emails if some conditions are met. I won't focus on the conditions, I just need to know what would be the best practice.

I have identified a few notifications: OnBeforeSendReceipt, OnAfterSubmitSave and OnBeforeSendMail.

I am not sure if these are the ideal one to use in case I don't want the email to be sent to either the sender (receipt) or the admin. And I don't want to save it in the database either.

If the notifications are the right ones, what would be the best method to use in order to prevent it from sending/saving?

I have identified: onBeforeRenderArgs.Submit.Delete() but I am not sure what it does exactly.

Thank you,

Adrian


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Adrian,

You don't specify where you're trying to prevent emails from being sent, but based on the notification you mention, I assume it's in Forms for Editors.

There isn't an officially supported way to prevent emails from being sent in Forms for Editors, but you might be able to "exploit" some of the validation rules that are used inside the emailing methods. I would have to know a little more about exactly what you're trying to achieve in order to assist you. Also, there isn't an officially supported way to prevent form submits to not be saved and I don't see any way for you to prevent this. You could delete the submit after, but that isn't a good solution either.

If you can confirm that you're using Forms for Editors, I'll add these feature requests to our backlog.

- Jeppe

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Jeppe,

Thank you for your answer.

Yes, I am using Forms for editors in DW9.5.x I apologise for missing this information in my post. I usually provide it.

The reason I need this is because we sometimes see empty forms coming through, although all the front-end tests show that the validations are working and no email should be able to override the required field validations.

And since we already have the notifications for various stages of the email, I thought that preventing the send would be easy.

If I understand correctly, Submit.Delete() would not do the trick. In this case, changing the RecipientEmail to an empty one could work?

How about the Save functionality. Is there any way I can prevent that?

Thank you,

Adrian

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Adrian,

That actually sounds more like a bug than something you should try and fix. However, I do understand that you'd want to prevent it temporary while the bug is being looked at.

My recommendation would be to contact the Service Desk and report the bug so we can investigate the issue. After that, you can implement a hacky solution to handle it in the short term. While there aren't any good solutions, you can always disrupt the execution with an exception or redirect. Or, if you only want to prevent the emails from being sent, you can listen for OnSendMail and OnSendReceipt and remove the recipient(s) of the MailMessage. However, if you let the execution continue and just block the emails, the GDPR consent gathering subsystem still kicks in, and you'd have to clean up both submits, submit data and consents to remove any trace of the empty submit.

In order to allow for this behavior with notification subscribers, we need to introduce at least one more notification and change the abilities of the others. This is not a change that would make it into the software until 9.7 or later but I'll add the feature requests to our backlog.

- Jeppe

 

You must be logged in to post in the forum