Email reports with images from database in the email body in Dynamics 365 for Finance and Operations

Let’s say that we want to email reports from Dynamics 365 for Finance and Operations with some attractive content in the email body including images. Beside static content, some email parts can be dynamic and specific for every report execution. Standard Dynamics 365 for Finance and Operations supports sending emails with attached reports, but without the email body and consequently, without any dynamic content. Also, using the built-in functionality you can set up the email subject only as a static text and you cannot even affect the email attachment name.

With Docentric's Email print destination you can edit all email parts and enhance them with dynamic content. You can insert placeholders which will be replaced with content before sending. Text placeholders are replaced with text, while image placeholders are replaced with images, e.g. loaded from the database.

Learn on how to insert a company logo in the email body >>

With placeholders and rich HTML content you can easily create a dynamic, rich and appealing emails. This functionality is fully supported by Docentric AX Free Edition, which brings many improvements for other print destinations as well.

Some placeholders are supported out-of-the-box for all reports; they are called standard placeholders. There are also custom placeholders that are specific per report, provided by an additional model called Docentric AX SSRS Replicas for commonly used reports such as Customer invoice and Purchase order. This article demonstrates how to introduce and implement an additional custom image placeholder, and how to use it in the email body.

Let's say that our scenario requires sending Sales order confirmation by email, in which we want to use additional placeholders: SalesTakerName and SalesTakerImage. In order to introduce these placeholders, we will first need to add the corresponding attributes to the method DocSalesConfirmDSP.overrideReportRunSettings().

Please note that we've added SalesTakerName as a text custom placeholder using the DocPlaceholderAttribute attribute, while SalesTakerImage has been added as an image custom placeholder using the DocPlaceholderImageAttribute attribute.

Then, in the same method, we need to add the code that fills the values of these attributes.

After the code is compiled, open Print management setup > Sales order confirmation and choose Docentric Email print destination. Enter the email body content and insert the Sales Taker Name and Sales Taker Image from the Fields drop down list. Text placeholders are inserted as @Placeholder@, while image placeholders are inserted as blank pictures.

 

In Source view you can see the <img> HTML tag and its attributes. Height/width define the image size in received emails. Default values are defined through DocPlaceholderImageAttribute, but you can change or remove them. If height/width are not defined, an email client will show the picture with the dimensions inferred from the image content.


Note that height/width are specified twice in two different attributes for better compatibility with various email clients. For example, MS Outlook considers only the height and width attributes and ignore height/width specified in the style attribute.

When you insert an image placeholder this is what you get:

You can omit the width dimension, which means that the width of the real image will be applied in the email body.

If you omit both height/width, the dimensions of the real image will be applied in the email body.

When editing content in Source view and clicking OK before anything else the changes might get lost. To avoid it click Source button again before clicking OK. This is a known issues that will be fixed in next releases.

Let's say that we want to send Sales order confirmation to the customer's primary contact email. In order to do that we need to set the To field to the @@ email token.

If we print Sales order confirmation using Use print management, the email with the attached report will be send to the customer's primary email address.

The sent email looks like this one below.

See also

Learn how to use a company logo in the email body >>
Download and use Sales Order Confirmation with image placeholders >>
Watch Video on How To Configure and Use Report Email Templates (from 3.3.9 ver) >>

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 >>