Bulk Updating Email Signatures in Dynamics 365

Nick Chin, 21 August 2019

Recently I needed to update the Email Signatures for all Dynamics 365 Users and insert information from the User record.

Currently this can’t be done using the out-of-the-box solution. Even though Email Signature templates are basically email templates you are unable to insert field values like the User’s Name, Job Title and Phone Number. Therefore, to bulk update users’ signatures I needed to use code.

There are two parts to updating the Email Signature:

•    Template
•    Code

Template:

The Template will contain the content for each user’s Email Signature and have placeholders for user fields, which will be replaced using code.

  • Create your Email Signature template and add placeholders for where you want to insert User information. This can be created in Word or a HTML editor. For example you can use placeholders like {full name}, {job title} and {telephone}

image

  • The easiest way to convert the Email Signature template into the required Dynamics 365 format is to create an Email Signature in Dynamics 365 and then paste the template into editor. 

image
Note: that images like email templates will need to be hosted on an internet facing website. URLs will need to be URL encoded. 
When copying to the Email Signature the formatting can change, especially when copying from Microsoft Word.

  • Once the Email Signature has been created in Dynamics 365, you will need to export the presentationxml field. You can’t use advanced find, so I used the XrmToolBox and the FetchXML Builder to get this data.
    The presentationxml is xml that is formatted as below and the signature content html encoded within:
    <emailsignature><presentationxml>{signature content}</presentationxml></emailsignature>

image

  • If the email signature format has changed after pasting it into the Email Signature, then you will want to fix this.

To help find where the formatting has changed, use the web browser’s Developer Tools to insert the Email Signature.

image

Here you can edit the html within the Presentation XML.

Additional Spacing

Additional line spacing can appear as “&lt;o:p&gt;&lt;/o:p&gt;” or the paragraph tag, this can also be within a span.

Spans

image

The {full name} is within two spans with different styles, this can cause incorrect formatting. Make sure the inner span is correct, in the example the “font-size” is missing, so the outer Span’s “font-size” will be used. Also you can remove the font styling from the inner span.

Padding / Margins

image

The padding often adds line spacing, so removing the 4.3pt so it becomes “padding:0pt 0cm 4.3pt 0cm;” to remove the top padding.

Images

image

If you copied from Word the links won’t be correct, normally the src or link to a temp location like “&lt;v:imagedata src="file:///C:/Users/nick/AppData/Local/Temp/msohtmlclip1/01/clip_image002.png" o:title=""/&gt;” will be removed.

Code:

Now I will cover how we can use Code to bulk update User’s Email Signatures using this Email Signature template. The Code will need to retrieve the users, then use the template to create an email signature for each user.

I used a C# Console App to run the User Email Signature update.

  • Save the Email Signature template from Part 1 as a text file, this is the easiest way to manage the templates and add the template location in the App.config, so this can be configured.
    Here is an example template below:
    <emailsignature><presentationxml>&lt;table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse;"&gt; &lt;tbody&gt;&lt;tr style="height:122.75pt;"&gt;&lt;/tbody&gt;&lt;/table&gt;</presentationxml></emailsignature>
    
  • Retrieve all the Users you want to update from Dynamics 365 and the fields required for populating the template.
  • Load your Template from the text file into a String, I used the C# function “File.ReadAllText”.
  • Replace the placeholders in the template like {full name}, {job title} and {telephone} with the fields from the User.

image

  • Now you create the Email Signature.

The email signature entity schema name is “emailsignature”
The fields that need to be set are:

image

It is always a good idea to do a few tests to confirm the signature is created correctly.

Here is what the created template from earlier will look like for my user:

image

Considerations:
•    Sometimes you may want to use different Email Signature depending on certain criteria.
•    The email signature may need to be updated periodically, so you may want to update the existing default email signature rather than create a new email signature record.
•    You don’t always want to set the Email Signature to default, sometimes users will need to review the email signature before manually setting it to the default.
•    This process can be improved to retrieve and update the field more dynamically.