Добрый день!
Столкнулся с непонятной проблемой, необходимо произвести рассылку по шаблону на 7000 контактов.
Вот этот код, взятый из SDK вполне рабочий и справляется с небольшими рассылками
Код:
SendBulkMailRequest bulkMailRequest = new SendBulkMailRequest();
// 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 = EntityName.contact.ToString();
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.
bulkMailRequest.Sender = GetEmailSenderMoniker(service);
// 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 async bulk e-mail request.
service.Execute(bulkMailRequest);
// Now that we have executed the bulk operation, we have to retrieve it using our tracking ID.
ColumnSet asyncColumns = new ColumnSet();
asyncColumns.Attributes = new string[] { "requestid", "statecode" };
QueryByAttribute bulkQuery = new QueryByAttribute();
bulkQuery.ColumnSet = asyncColumns;
bulkQuery.EntityName = EntityName.asyncoperation.ToString();
bulkQuery.Attributes = new string[] { "requestid" };
bulkQuery.Values = new object[1];
bulkQuery.Values[0] = trackingId.Value;
// Retrieve the bulk e-mail async operation.
BusinessEntityCollection aResponse = service.RetrieveMultiple(bulkQuery);
// Monitor the async operation through polling.
const int ARBITRARY_MAX_POLLING_TIME = 60;
int secondsTicker = ARBITRARY_MAX_POLLING_TIME;
asyncoperation createdBulkMailOperation = null;
while (secondsTicker > 0)
{
// Make sure that the async operation was retrieved.
if (aResponse.BusinessEntities.Length > 0)
{
// Grab the one bulk operation that was created.
createdBulkMailOperation = (asyncoperation)aResponse.BusinessEntities[0];
// Check the operation's state.
if (createdBulkMailOperation.statecode.Value != AsyncOperationState.Completed)
{
// The operation has not yet completed. Wait a second for the status to change.
System.Threading.Thread.Sleep(1000);
secondsTicker--;
// Retrieve a fresh version the bulk delete operation.
aResponse = service.RetrieveMultiple(bulkQuery);
}
else
{
// Stop polling because the operation's state is now completed.
secondsTicker = 0;
}
}
else
{
// Wait a second for the async operation to become active.
System.Threading.Thread.Sleep(1000);
secondsTicker--;
// Retrieve the entity again.
aResponse = service.RetrieveMultiple(bulkQuery);
}
}
// When the bulk e-mail operation has finished, all sent e-mail messages will have a status of "Pending Send" and
// will be picked up by your e-mail router. Or, you can then use BackgroundSendEmail to download
// all the e-mail messages that were created by using the SendBulkEmail message. See the BackgroundSendEmail sample for an example.
#region check success
// Validate async operation succeeded.
if (createdBulkMailOperation.statecode.Value == AsyncOperationState.Completed)
{
success = true;
}
При отправить на 7000 контактов, не появляется никаких ошибок в логах (уровень отладки в конфиге EmailRouterа на 3 менял, ошибок нет), но и почта не уходит и даже соответствующие активности не создаются для контактов. Даже не знаю в чем проблема и как её решать. В хвосте функции объект createdBulkMailOperation.statecode приобретает значение Suspensed.
Пробовал увеличивать значение ARBITRARY_MAX_POLLING_TIME до 6000, не помогло, функция отрабатывает больше времени, но писем и активностей не появляется.