This documentation is archived and is not being maintained.

SendBulkMail Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online and offline

Sends bulk e-mail messages.

The relevant classes are specified in the following table.



To use this message, pass an instance of the SendBulkMail class as the request parameter in the Execute method.

For a list of required privileges, see SendBulkMail Privileges.


The following code example shows how to use the SendBulkMail message.

// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create the bulk mail request.
SendBulkMailRequest bulkMailRequest = new SendBulkMailRequest();

// TODO: Use contacts that are already created.
object[] contactIds = new object[2];
contactIds[0] = new Guid("7E91958D-C8A1-404C-AC2C-9C474FB2427B");
contactIds[1] = new Guid("44E05740-607B-47AA-ABD6-13A007E2DD85");

// Create a query expression for the bulk operation to use to retrieve the contacts in our e-mail list.
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "contactid";
condition.Operator = ConditionOperator.In;
condition.Values = contactIds;

FilterExpression filterExpression = new FilterExpression();
filterExpression.Conditions = new ConditionExpression[] { condition };

ColumnSet returnColumns = new ColumnSet();
returnColumns.Attributes = new string[] { "contactid" };

QueryExpression queryRequest = new QueryExpression();
queryRequest.ColumnSet = returnColumns;
queryRequest.EntityName =;
queryRequest.Criteria = filterExpression;

// Attach the contact query to the bulk e-mail request.
bulkMailRequest.Query = queryRequest;

// Get a system user to use as the sender.
Moniker emailSender = new Moniker();
emailSender.Id = new Guid("9DAEE309-A3D6-470C-80E2-DDC657BAFC16");
emailSender.Name = EntityName.systemuser.ToString();
bulkMailRequest.Sender = emailSender ;

// Set the RegardingId to the e-mail sender.
bulkMailRequest.RegardingId = bulkMailRequest.Sender.Id;
bulkMailRequest.RegardingType = EntityName.systemuser.ToString();

// Use a built-in e-mail template.
// Note: The e-mail template's 'template type' must match the type of customers
// in the e-mail list. Our list contains contacts, so our template must be for contacts.
bulkMailRequest.TemplateId = new Guid("07B94C1D-C85F-492F-B120-F0A743C540E6");

// Create a tracking ID for the bulk operation to monitor its progress.
RequestIdOptionalParameter trackingId = new RequestIdOptionalParameter();
trackingId.Value = Guid.NewGuid();

// Attach the tracking ID to the bulk e-mail request.
bulkMailRequest.OptionalParameters = new OptionalParameter[] { trackingId };

// Execute the asynchronous bulk e-mail request.

See Also




© 2010 Microsoft Corporation. All rights reserved.