Answered by:
How to run plug-in on send of email

Question
-
I am looking to trigger a plug-in on send of an email within Dynamics but can't seem to get it to trigger.
I have tried Messages, BackgroundSend, SetState, SetStateDynamicEnity and Send, both with Async and Sync Execution.
I am using CRM 2011 Online.
Any help appreciated.
Wednesday, July 20, 2011 2:49 PM
Answers
-
Hi,
Try registering pluign step for Send message on email entity in Pre-Operation or Post-Operation stage, CRM saves email message and then fire Send message. The Message will pass EmailId, IssueSend and TrackingToken in context paramters. your code in plugin would be:
Guid jj_EmailId = Guid.Empty; bool jj_IssueSend = false; string jj_TrackingToken = string.Empty; switch (context.MessageName) { case "Send": if (context.InputParameters.Contains("EmailId") && context.InputParameters["EmailId"] is Guid) { jj_EmailId = (Guid)context.InputParameters["EmailId"]; } if (context.InputParameters.Contains("IssueSend") && context.InputParameters["IssueSend"] is bool) { jj_IssueSend = (bool)context.InputParameters["IssueSend"]; } if (context.InputParameters.Contains("TrackingToken") && context.InputParameters["TrackingToken"] is string) { jj_TrackingToken = (string)context.InputParameters["TrackingToken"]; } break; }
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Proposed as answer by Jehanzeb.Javeed Wednesday, July 20, 2011 5:17 PM
- Marked as answer by David Small Thursday, July 21, 2011 8:45 AM
Wednesday, July 20, 2011 5:17 PM -
Thanks Jehanzeb.
I changed the Pipeline Stage to Pre-Operation and it fired perfectly.
Thanks for the other info on InputParameters.
Does anyone have a link to documentation about what is pass in InputParameters on different plug-in Message Types??
- Marked as answer by David Small Thursday, July 21, 2011 8:48 AM
Thursday, July 21, 2011 8:48 AM
All replies
-
I would suggest Send of an Email entity. How do you know this is not firing? Do you have a local sandbox environment where you have tried to check if the platform message is firing by attaching a debugger to a local process on a dev server?
Is your online email router configured properly?
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!- Proposed as answer by Jamie MileyModerator Wednesday, July 20, 2011 3:41 PM
- Unproposed as answer by David Small Wednesday, July 20, 2011 3:46 PM
Wednesday, July 20, 2011 3:20 PMModerator -
It is a Microsoft Hosted CRM Online.
I have set the first line of code to throw an error so i know at least the plug-in is firing on that event.
I have not looked at an online email router sorry.
Regards
Wednesday, July 20, 2011 3:24 PM -
You will require a properly configured email router to send mail in CRM. That might be your problem.
Did the first line of code execute properly and throw the expected error? If so I think your question is probably answered.
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!Wednesday, July 20, 2011 3:41 PMModerator -
Sorry it doesn't throw the error and that is why I know it hasn't triggered.
I would like the plug-in to action on status change as I don't really care at this point if the email is actualyl sent.
Thanks again
Wednesday, July 20, 2011 3:47 PM -
Hi,
Try registering pluign step for Send message on email entity in Pre-Operation or Post-Operation stage, CRM saves email message and then fire Send message. The Message will pass EmailId, IssueSend and TrackingToken in context paramters. your code in plugin would be:
Guid jj_EmailId = Guid.Empty; bool jj_IssueSend = false; string jj_TrackingToken = string.Empty; switch (context.MessageName) { case "Send": if (context.InputParameters.Contains("EmailId") && context.InputParameters["EmailId"] is Guid) { jj_EmailId = (Guid)context.InputParameters["EmailId"]; } if (context.InputParameters.Contains("IssueSend") && context.InputParameters["IssueSend"] is bool) { jj_IssueSend = (bool)context.InputParameters["IssueSend"]; } if (context.InputParameters.Contains("TrackingToken") && context.InputParameters["TrackingToken"] is string) { jj_TrackingToken = (string)context.InputParameters["TrackingToken"]; } break; }
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Proposed as answer by Jehanzeb.Javeed Wednesday, July 20, 2011 5:17 PM
- Marked as answer by David Small Thursday, July 21, 2011 8:45 AM
Wednesday, July 20, 2011 5:17 PM -
Thanks Jehanzeb.
I changed the Pipeline Stage to Pre-Operation and it fired perfectly.
Thanks for the other info on InputParameters.
Does anyone have a link to documentation about what is pass in InputParameters on different plug-in Message Types??
- Marked as answer by David Small Thursday, July 21, 2011 8:48 AM
Thursday, July 21, 2011 8:48 AM