I want to edit the E-mail template in my Dynamics CRM 2011 solution.
I will add a combo box to the form that allows a user to decide what classification the email should be eg. "A", "B" or "C"
This helps our email gateway know what to do with certain mail with regard to archiving etc. Also setting the header will make it harder for a user (recipient) to declassify (lowering a classification) which could easily be done if we just shoved the classification in the subject line (and yes I understand we are still vulnerable to copy and paste but try telling my client that).
Just before the email is sent is there an event where I can get the mail item and add mail headers and also manipulate things like the subject line or some other editable field.
I have written an Outlook Add-in that runs this code on send and basically want to know where I should put similar code in Dynamics.
private Dictionary<string, List<string>> _classifications;
private const string ProtectiveMarkingSchemaName = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-Protective-Marking";
private const string Version = "0.1";
private const string Namespace = "xyz.com";
void ApplicationItemSend(object item, ref bool cancel)
{
// GUARD
if (!(item is MailItem)) return;
if (ClassificationDropDown.SelectedItem == null ||
String.IsNullOrEmpty(ClassificationDropDown.SelectedItem.Label))
{
cancel = true;
return;
}
// CURRENT ITEM
var mailItem = (MailItem)Globals.ThisAddIn.Application.ActiveInspector().CurrentItem;
// PREPARE MARKING
var origin =
Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;
var classification = new StringBuilder();
classification.AppendFormat("SEC={0}", ClassificationDropDown.SelectedItem.Label);
if (DisseminationDropDown.SelectedItem != null)
{
if (!String.IsNullOrEmpty(DisseminationDropDown.SelectedItem.Label))
{
var cat = DisseminationDropDown.SelectedItem.Label;
classification.AppendFormat(", CAVEAT={0}", cat);
}
}
// FILTHY HACK
if (mailItem.Subject == null)
{
mailItem.Subject = " ";
}
// FIND OLD MARKINGS
var start = mailItem.Subject.IndexOf('[');
var end = mailItem.Subject.LastIndexOf(']');
if (end - start > 0)
mailItem.Subject = mailItem.Subject.Remove(start, (end - start) + 1);
// APPLY MARKING
mailItem.Subject = String.Format("{0} [{1}]", mailItem.Subject.TrimEnd(), classification);
mailItem.PropertyAccessor.SetProperty(
ProtectiveMarkingSchemaName,
String.Format("[VER={0}, NS={1}, {2}, ORIGIN={3}]", Version, Namespace, classification, origin));
}