Sending Emails Using Docentric APIs

Instead of using the built-in SysEmailTable::sendMail() method for replacing placeholders in an email’s body and subject before sending it, you can use the DocEmailTemplateManager::sendMail() method that offers you more options such as an email body with dynamic tables, multiple email attachments, using Cc and Bcc recipients, etc.

Let’s see how it works on an example. Assume that you have an email message with the ID CnfmOrder in your Email Templates setup, and that you need to send an email notification to a customer (sara@gmail.com) that her sales order with ID 000725 is confirmed.

The only thing you have to do is to invoke the DocEmailTemplateManager::sendMail() method with the proper parameters, of course under condition that you have created a custom Docentric's ETH (Email Template Handler) class, which provides both definition and values for your custom placeholders.

You can see here how the used ETH class should look like >>

The second approach you might take is to fill the Placeholder name -> Placeholder value mapping outside your custom Docentric’s ETH class before sending an email as shown below. Just make sure that the names of your custom placeholders are the same as those used in Docentric email body editor, i.e. those defined in the ETH class.

The best practice is to use string constants for placeholder names in a custom Docentric’s ETH class, so you can use them to create a map for defining placeholder names and friendly names shown in Docentric email body editor, and also to fill a mapping between placeholder and their values.

Resources

Download custom email handler class >>
See how to create an email body with a dynamic table >>
Read how-to manual on improved Email templates >>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Docentric respects your privacy. Learn how your comment data is processed >>

Docentric respects your privacy. Learn how your comment data is processed >>