I have a plugin which triggers pre-operation on update of email.
In the code I update the address used on the activityparty for a single recipient, and then I update the email.
When the email is sent, however, it still sends to the primary email address (emailaddress1 on Contact) even though I've specified emailaddress3 (even if I hard-code the email address and add it to the addressused it still sends to the primary address).
Code below:
var recipient = ((EntityCollection)email.Attributes["to"]).Entities.FirstOrDefault<Entity>();
var to = (EntityReference)recipient.Attributes["partyid"];
var contact = service.Retrieve("contact", to.Id, new ColumnSet("emailaddress3"));
((EntityCollection)email.Attributes["to"]).Entities[0].Attributes["addressused"] = contact.Attributes["emailaddress3"];
service.Update(email);
System is CRM 2016 on-premises
*This post is locked for comments