How to override the default email address when sending an email to a contact
On a recent Dynamics 365 project we had a requirement to protect the contact’s email address. Naturally, field level security was the obvious choice to protect the email address. Since protecting the primary email address (emailaddress1) is not allowed, we had to introduce a new custom email field.
Therein lay the challenge. When sending an email to a contact, CRM automatically refers to the default emailaddress1 field. However, for special case contacts, this email address needs to be stored in the, field-level security protected, new custom email address field. Storing this value in the default email address would defeat the purpose of protecting its value. So, the challenge our Technical Architect faced was, how to send an email to special contacts.
In short, the solution is to intercept the newly create email record and replace the ‘addressused’ attribute.
Below is sample code demonstrating how to accomplish this using a plug-in or custom workflow plug-in.
• Plug-in to send to alternate email address.
• Custom workflow activity, used by custom dialog to send an email.
This plug-in code changes the email address used to send to the contact. It does not, however, address the above requirement of preventing non-authorized personnel of sending emails to special case contacts.
This code, if executed by a non-authorized person, would fail. The reason is that the un-authorized person does not have field level security to the protected email address.