Problem: We use the CRM plugin for Outlook to automatically log into our support emails, but internal emails between employees (some of which contain confidential information) are also recorded.
Ideal solution: I am trying to write a pre-event (message "create a letter") to block the automatic maintenance of internal letters, but (apparently) the only way to stop the message from being executed is to throw an exception at the stage of the preliminary event, but this always causes an error message to be displayed in Outlook (which we obviously don’t have). According to the documentation, only "InvalidPluginExecutionExeception" should show messages to the user, but this is not so, since all exceptions lead to an error message in Outlook for users.
Potential solution: There is also a “CheckPromoteEmail” message that (according to the documentation) determines whether to promote the email in CRM (I assume that “promotion in CRM” means “make a mailbox for storage in CRM”), but I don’t could find nothing in a context that would let me tell CRM not to promote email. Is there some kind of flag buried in the context that I can set, or in some way in order to invlaidate the email so that my own CRM logic decides not to store it?
Workaround: The only other solution I know of (mentioned here ) is to simply clear the subject and contents of the email after it was created, but I would rather prevent email from being created in the first place than editing or deleting it after that how time and resources were wasted creating an email.
Is there any way to stop the operation from the plugin? Or from anywhere? If this does not happen, does anyone know why Microsoft did not provide this feature? They already have rollback functionality from swap under the hood in case of a malfunction, why don't they give me a way to trigger a rollback?
Here is my code in case it helps in answering my question:
public class InternalEmailFilter : IPlugin { void IPlugin.Execute(IServiceProvider serviceProvider) { IPluginExecutionContext _context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); Entity e = (Entity)_context.InputParameters["Target"]; bool shouldStore = ShouldStoreInCRM(e); if (shouldStore == false) { throw new Exception(); //attempting to stop the operation without an InvalidPluginExecutionException, but still results in error message to user } } protected bool ShouldStoreInCRM(Entity e) { List<Entity> parties = new List<Entity>(); var atttributes = e.Attributes; if (atttributes.ContainsKey("to") == true) parties.AddRange((atttributes["to"] as EntityCollection).Entities); if (atttributes.ContainsKey("from") == true) parties.AddRange((atttributes["from"] as EntityCollection).Entities); if (atttributes.ContainsKey("cc") == true) parties.AddRange((atttributes["cc"] as EntityCollection).Entities); if (atttributes.ContainsKey("bcc") == true) parties.AddRange((atttributes["bcc"] as EntityCollection).Entities); foreach (Entity p in parties) { if (p.LogicalName == "activityparty" && p.Attributes.ContainsKey("addressused") == true && p.Attributes["addressused"] != null) { if (p.Attributes["addressused"].ToString().ToLower().Contains("@ourdomain.com") == false) { return true; //someone connected in the email is not an employee, store the email } } } return false; //everyone was an employee, do not store } }
source share