Setting email to “Pending Send” doesn’t work – Dynamics 365

Couldn’t get an email generated by a workflow to send using the “classic” method of changing the status to “Pending Send”. The email would just sit there in Pending Send status forever with an alert message that said “This message has not yet been submitted for delivery,” along with a non-helpful suggestion to see help.

Turns out, this method of triggering an email to send doesn’t work anymore (as of 2015 update 1). It took me a while to tweak my google-fu to locate this page, but it certainly confirmed my suspicions.

I simplified the code from that page even further below. PLEASE NOTE, I’m only using this to send notifications from workflows, so tracking tokens in the subject line are not generated. If you need to use this with tracking tokens, use the code from the original link.

using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Crm.Sdk.Messages;

public class SendEmail : CodeActivity
{
    [RequiredArgument]
    [Input("Email to send")]
    [ReferenceTarget("email")]
    public InArgument<EntityReference> Email { get; set; }

    protected override void Execute(CodeActivityContext ec)
    {
        var context = ec.GetExtension<IWorkflowContext>();
        var factory = ec.GetExtension<IOrganizationServiceFactory>();
        var service = factory.CreateOrganizationService(context.UserId);

        var email = Email.Get(ec);
        var req = new SendEmailRequest() { EmailId = email.Id, IssueSend = true };
        service.Execute(req);
    }
}

Maybe Microsoft will change this in a future update, but for now it looks like you’re stuck needing a custom workflow plug-in for your deployment.

2 Replies to “Setting email to “Pending Send” doesn’t work – Dynamics 365”

  1. It’s nice of you to simplify the code but it’s not going to work if your instance is configured to use tracking tokens.

    1. Thanks for your reply! Very true, I forgot about that feature because we’re only using workflows to send system notifications, which we don’t want to track anyway. I’m adding a note to the post with another link back to the original code.

Leave a comment