Removing email from CRM queue

Currently if there is email in queue and if user manually creates case then case gets creates but email remains in the CRM queue.

Another scenario is that there is automated workflow which creates case for the email which comes in queue and workflow creates case fine but email remains in the queue.

For above two problems there is not out of the box method to remove or detach the email from the queue. However when I check CRM 4.0 SDK there is API DetachFromQueueEmailRequest Based on which I have created following generic custom workflow which takes queue id and email id as Input and removes the relevant email from the relevant queue.

Following is full code snippet for this..

Register this custom workflow using Plug in Registration Tool and you can use this utility in CRM workflow screen now…

Code can be downloaded from following link
View & Download Code File


17 thoughts on “Removing email from CRM queue

  1. Jeffrey Smith

    I cannot get this to work for me. I am having a problem when I attempt to register this code as an assembly in the plugin registration tool. Maybe you could give me a pointer? I can build this code find, then when I attempt to load the assembly in the plugin registration tool I get:

    Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly ‘System.Workflow.Activities, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.

    doesn’t seem to matter where I put the microsoft.crm.sdk file. I’m not sure how to get past this error and theres nothing on google…

    I tried referencing the two dlls in the SDK folder location, I tried putting them in the same folder as my built dll, I tried putting them in the same folder as the plugin reg tool, all with the same results. Thoughts?

    1. mayankp Post author

      Hi Jeff,

      have you tried followingn steps?

      1) Place Microsoft.Crm.Sdk.dll in the same directory as the Custom Workflow Activity.

      2) Add reference to Microsoft.Crm.Sdk.dll to Plugin Registration Tool project and place the DLL in the same place as the executable.

      Also check following links for the same error

  2. Jeffrey Smith

    Thanks so much for the response.

    1. By Custom Workflow Activity do you mean my built project dll? In my projects …bin/debug/ folder I have:
    ActivityLibrary3.dll (my assembly I wish to register)

    same error persists.

    2. Added reference, builds without error and then I put the microsoft.crm.sdk.dll in the same folder as the pluginregistration.exe but same error persists.

    Link 1: no spelling errors
    Link 2: no change.
    Link 3: I check the GAC on my machine with gacutil /i microsoft.crm.sdk.dll and I get:

    Assembly already exists in cache. Use /f option to force overwrite
    I force install but the same error persists.

    I think I’m out of luck. Maybe I’ll try this on a different machine. I’m using windows 7 x64 with Visual Studio 2010 Professional trying to publish assembly to CRM 4.

  3. mayankp Post author

    Okay, few more ides to fix this..

    1.are you doing disk deployment or database deployment?

    in both the case file should be on CRM Server and you must run the Plug in Reg tool on CRM Server only…it seems to be you might be running this tool from local system if this the case it will not work..

    and for disk deployment assembly must be put in CRM\Server\bin\assembly folder…

    2. have you tried doing this with VS 2008 or VS 2005. VS 2010 is based on .Net 4.0 which might not be supported for this.

    let me know how you get on with this…

  4. Jeffrey Smith

    I went to a workstation that had Visual Studio 2008 on it, and made my dll. I was using the pluginregistration from my workstation. I moved the exe over to the crm server and after everything, got it working. Thanks so much, you got me going in the right direction.

  5. Jeffrey Smith

    I went to a workstation that had Visual Studio 2008 on it, and made my dll. I was using the pluginregistration from my workstation. I moved the exe over to the crm server and after everything, got it working. Thanks so much, you got me going in the right direction.

    As for the workflow step, I see it in my options now but when adding it it doesn’t seem to work. do I need to enter anything in the properties?

    I have a workflow that checks the email, if its to techsupport then it sends an email autoresponse and then this activity, which should delete the email from the queue. I send a test message and I get the autoresponse, so the workflow is triggering, I see the incoming email and autoresponse in activity, but the original email is still in the queue. Hopefully I’m just missing something in the properties so I don’t need to embark upon troubleshooting…

  6. mayankp Post author

    Yes, you need to pass properties in this custom workflow..

    email – select email from the workflow right hand side..

    queue – select relevant queue..

    once you have this set then it would work fine..

  7. Chris H

    Ok, I am looking at this and I think I need it because my queues are getting full of email that is already linked to cases on the ‘regarding’ field.

    What about mail that is not associated to a case or anything else? I want to leave that in the queue for ‘human’ processing.

    I assume I would put this workflow on the creation of an email task, but how do I tell if this particular email is in a queue? If you don’t test for the queue assignment, won’t the workflow fail?

    I guess what I need is instruction on how to impliment the workflow so it will remove mail from the queue that has been linked, but leave the stuff that hasn’t been linked.

    1. mayankp Post author

      Hi Chris,

      The way we implemented is that we run workflow on email create and we check if is for particular queue then we create case and then assign created case to queue and then finally remove email from the queue (becuase case is already created).

      This particular code is remove email from any queue and it takes queue name and email as perameter..

      how do you create case in your scenario? if you are doing in the workflow then that workflow should include option to remove email from queue once case got created..

  8. Zarko

    Does anybody know how to do this with crm 2011 libraries, I can’t find anything similar to DetachMailFromQueueRequest class.

    Thanks in advance

  9. Pingback: CRM 2011: Removing Email from queue « MayankP's Blog

  10. Bill Faulk

    What did you end up doing for CRM 2011 since DetachFromQueueEmailRequest doesn’t exist any more? Lots of examples in the SDK for adding to a queue and none on removing something.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s