问题
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.
回答1:
If this is post-update and from address field hasn't changed during update, it will not be passed to plugin in Target parameter. You need to add pre/post image and add from address property to this image. Then you'll be able to get value from image
回答2:
Try checking the sender attribute of the e-mail message. It should contain the actual e-mail address used in the from field.
来源:https://stackoverflow.com/questions/16299492/accessing-email-senders-address-in-dynamics-crm-plugin