Accessing email sender's address in dynamics CRM plugin

老子叫甜甜 提交于 2021-02-10 09:44:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!