From Docentric version 3.4.6. a new delegate (DocPrintDestSettingsEmail.removeInvalidEmailAddressesDelegate()) exists for cleaning the To, CC and BCC fields of invalid emails when printing to the Docentric email print destination.
This functionality can be useful in cases where we use Docentric placeholders in the address (To, CC, BCC) fields, whether printing interactively or via a batch job, since these aren’t validated on the print destination settings form.
For example, here we are using the @OrderEmail@ placeholder on the customer invoice (SalesInvoice) report:
This placeholder will take the content from the email field that’s on the header of the Sales order:
When we now try to print the related customer invoice we will get the following warning message, but the email will still go through to all the valid emails:
The default behavior has not been changed and the new logic for removing invalid emails will only trigger if there is a subscriber that enables the relevant parameters.
How to enable
To enable this new functionality you’ll need to subscribe to the new delegate, please note however that only a single subscriber is allowed for this delegate.
If you would like to learn more about delegates, we have a nicely written article on the topic here.
First you’ll need to create an event handler method for it by going to the DocPrintDestSettingEmail class and copying the event handler method like so:
Then you can create a new class (for example DocRemoveInvalidEmailsSubscriber) and paste the event handler method there.
In this new method we need to create a new object of type DocCleanEmailsResult and set the parameters that we wish to use.
The constructor for this result class which contains the parameters looks like this:
The parameters that are available are:
- _cleanEmailTo, _cleanEmailCc and _cleanEmailBcc which represent the fields that we want to clean. Off by default.
- _showWarningMsg which indicates whether or not we want to show a warning message containing the invalid fields that were removed. On by default.
- _isCleaned which is used to indicate that the invalid emails have already been cleaned. Used for skipping the default Docentric logic in case custom logic is in place. Off by default.
So, if we wanted to enable the functionality for all fields, the delegate subscriber would look like this:
Now we just build and we’re ready to enjoy the new functionality!
Working example subscriber class.