Friday, January 30, 2015

How to send an email via workflow without using the Send Email step (use create step instead)

You might already wonder: why the heck wouldn’t I just use the awesome “Send Email” step available in the workflow designer?! This post explains why but how to easily work around it.

We recently came across a scenario in which we wanted to automate some emails via workflows. However, we also needed to add some attachments to those emails based on some logic. Unfortunately in the current CRM workflow designer you cannot have any logic to add dynamic attachments to your email when you use the “Send Email” step of a workflow definition. However, we knew we could develop a simple custom workflow activity that could add attachments to the email. The problem was: If you use a Send Email step, the email is sent immediately and you have no way modify the email with attachments.

So the easy work-around is to first use the “Create” step in the workflow designer to first create an instance of the email an populate all the fields as desired. Then you can add additional steps that take actions on those emails, for example, a custom step that adds attachments to it. Because the records from the “Create” steps are available in all subsequent steps in the workflow, you can always reference it back and update it as many times as you want.

Once you have manipulated your email and added the relevant attachments with a custom step you are finally ready to send it, and this is the tricky part. How can you add a step to send an existing draft email? Well, certainly you could develop another custom workflow activity to do so. However, the solutions turns out to be much easier: All you need to do is set the status of the email to “Pending Send” and set the No. of Delivery Attempts to 0. Once you do this, then the email router will be ready to deliver the email (of course this is assuming you have configured your email router!).

So with a simple “Change Status” step and a subsequent “Update” step you can force the workflow to send the email you created!

image

image

5 comments:

  1. We had similar requirement, OnClick of Ribbon Button we have to Create an Email using email Template and to attach Docs from the Notes, but not to send instead they should be able to preview it. We used Plug-in and Service.Create.

    Creating email goes to activity section and available on the form itself (2013 forms). Still USer has to click one more time to preview the email.

    I was thinking to pick your brain if you see some possible solution that, right after clicking Ribbon Button the newly created email in Draft mode should be open for User to Preview and then they can send. I found this link but don't know if this is ideal solution. Here is the link - http://ankit.inkeysolutions.com/2014/07/dynamics-crm-20132011-on-custom-ribbon_25.html

    Any Advice would be great.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Hi,

    I've changed the email status to Pending Send and then updated the Delivery Attempts to 0 but the email stays in Pending Send status forever.

    Am I missing any needed configuration?
    (I'm using CRM 2013 online)

    Thanks,
    Rodrigo

    ReplyDelete
    Replies
    1. Is your email router configured? I mean, there could be many other reasons why your emails are not getting sent, which is beyond the scope of this post. If you try a send email step in a workflow or manually send an email by creating an email activity. If that does not work is because you have not properly configured the email router.

      Delete
  4. thanks Gonz.. by the way, I don't think this method works if you are using server side sync. Any experience with that and a way to work around?

    Thanks-
    Curt

    ReplyDelete