We would like to be able to send emails to something other than system users, accounts and contacts. Meaning, we have a custom entity containing an email address, and a workflow which is supposed to send a message to that address.
Alas, the default mechanisms in workflows don't allow sending to anything BUT the standard entities, so I'm trying to write a plugin to change the email's recipient based on the type of "regarding entity".
I am, however, struggling with actually changing the email itself!
var email = ctx.EmailSet.Where(e => e.Id == localContext.PluginExecutionContext.PrimaryEntityId).Single(); var party = newEntity("activityparty"); party["addressused"] = "some@email.com"; email["to"] = newEntity[] { party }; ctx.UpdateObject(email); ctx.SaveChanges();
This is my experimental post-create code - my only goal is to change the email address of the recipient to "some@email.com". However, the whole thing crashes on SaveChanges without any specific error.
I've also tried a pre-create code which did almost the same thing (email was taken from PluginExecutionContext.InputParameters["Target"]). The strange part was that the pre-create code didn't throw any exceptions, but no changes would be made.
What's going on? How can I change that recipient?