CRM 2011 – SendEmailRequest Not Working?

There is one “gotcha” when using the SendEmailRequest in the Microsoft Dynamics CRM 2011 SDK. I have seen questions asked throughout the community where developers are trying to programmatically send an e-mail, but the recipient never receives it. The e-mail message appears in the Activities list and also has a status of “Sent”, so why doesn’t it ever reach the recipients mailbox?

The answer is very simple! The SendEmailRequest includes a property called IssueSend which actually allows the e-mail to be sent from Outlook or via the E-mail Router – depending on your User settings for processing outgoing e-mails. If you set this property to true, the e-mail message will actually get sent.

Let’s take a look at the two scenarios. The screenshot below shows two e-mail activities in CRM that were programmatically sent via the SendEmailRequest. The first e-mail in the list has IssueSend = false while the second one has IssueSend = true.

capture

Notice the differences in the Status Reasons. The first e-mail is created in CRM with a status of Sent, even though the e-mail does not actually get sent. The second e-mail is in a Pending Send state which means that CRM is waiting for it to be sent via Outlook or the E-mail Router. Once it has been processed, the status will change to Sent.

For those who are interested, here is what the source code looks like to create and send an e-mail.

Entity email = new Entity("email");
email["subject"] = "Testing SendEmailRequest";
email["description"] = "I wonder if this will actually send???";

Entity from = new Entity("activityparty");
from["partyid"] = new EntityReference("systemuser", new Guid("F0B00160-9771-E211-84EA-00155D04DC01"));

Entity to = new Entity("activityparty");
to["partyid"] = new EntityReference("systemuser", new Guid("F0B00160-9771-E211-84EA-00155D04DC01"));

email["from"] = new Entity[] { from };
email["to"] = new Entity[] { to };

Guid emailId = _sdk.Create(email);

_sdk.Execute(new SendEmailRequest
{
    EmailId = emailId,
    IssueSend = true,
    TrackingToken = "CRM"
});

If you’ve reached this blog post, chances are that you’re having trouble with e-mails not being sent. I hope that the information above has answered your question and clears all headaches!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s