I am writing a Dynamics CRM 2011 plugin that hooks into the Email entity's post-update event (stage 40 of the pipeline), and am having trouble accessing the From address of the email at this stage in code.
We have set up an email router that forwards on emails sent to a specific address to Dynamics CRM. They end up in the service queue as Email entities. When I open those records in the frontend, the From address is visible (and linked to the relevant user/contact if applicable).
However, if I attempt to access the From property of the email entity in code, it is null. Example:
protected void ExecutePostEmailUpdate(LocalPluginContext localContext)
{
if (localContext == null)
{
throw new ArgumentNullException("localContext");
}
var entity = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];
var email = entity.ToEntity<Email>();
var from = email.From != null ? email.From.First().Id.ToString() : "[null]";
this.Log("Email from: {0}", from);
}
In all cases, I get "Email from: [null]" in my log.
Does anyone have any suggestions? There is a requirement to do something to the related incident (if one is created from the email) and for this, I need to see who the email was from.
Thanks.