brandonseydel/MailChimp.Net

Error sending campaign right after create

Closed this issue · 4 comments

Hi, I'm creating a regular campaign and everything seems to be working fine, but I keep getting an error when I try to send the campaign.
I get the error: Your Campaign is not ready to send.

However, when I go to MailChimp site, my campaign is listed as Draft and if I go into the campaign, Send button is enabled; if I hit it, it sends successfully.

This is how I'm creating the campaign:
var camp = new Campaign {
Type = CampaignType.Regular,
CreateTime = DateTime.UtcNow,
Settings = new Setting {
ReplyTo = campaignModel.ReplyTo,
SubjectLine = campaignModel.Subject,
FromName = campaignModel.FromName,
Title = campaignModel.Title,
TemplateId = campaignModel.TemplateId,
PreviewText = campaignModel.PreviewText,
FolderId = campaignModel.FolderId
},
Recipients = new Recipient {
ListId = campaignModel.ListId
}
};
return await mailChimp.Campaigns.AddAsync(camp);

Help is appreciated.

I'll guess you create the list during the creation of the campaign?
If yes: This maybe the culprit.

A list will always first processed by MailChimp which can take some time (depend on the size).
So if you create a list on MailChimp and switch to campaign you could also see, that you're not able to send the campaign, because the list is not yet finished in processing.

So in my case I use a while loop

bool readyForSend = false; 
while (readyForSend == false)  
{  
    Thread.Sleep(60000);
    var mailChimpManager = new MailChimpManager("XXX");
    var result = await mailChimpManager.Campaigns.SendChecklistAsync(mailchimpCampaignId);
    readyForSend = result.IsReady;
}

await MailChimpHelper.SendCampaign(mailchimpCampaignId);

Maybe there is an optimization possible with Webhooks, but currently this works good with HangFire and the customer didn't yet complained about these minutes of "delay".

Maybe some sort of built in rertry logic should be used on creations across the entire api to handle these use cases?

@brandonseydel
It's not easy to answer.

My Opinion

I think it's better to mention in the Readme.md that check Campaigns.SendChecklistAsync before Campaign.SendAsync is recommended.

The long explanation

I'll guess that Campaign.SendAsync and Campaign.ScheduleAsync (not yet used, therefore not sure if it's require) requires, that Campaign.IsReady is true. So it would make sense but...

Campaign.IsReady does check several other requirements.
In my example I can check Campaign.IsReady because I'll take care that everything else in the campaign is properly set. That is something we cannot assume by default within the wrapper.

Maybe we could add the Campaigns.SendChecklistAsync within both calls and return an Exception before we even send/schedule the campaign. So it's only an optimization for error handling.

If we focus only on the recipients itself:

As mentioned the size of the Recipients will affect the time until a campaign will be ready to send.

Currently I'll add around 2'300 recipients with Members.AddOrUpdateAsync which takes about an hour. In my case the Campaign is usually ready within 3 minutes after I've added the last recipient.
I'll assume that the new BatchList will reduce my processing time on create the list but it still have to wait until it's processed by MailChimp.

So what could we do?
For example we could first call (without a delay) a Campaigns.SendChecklistAsync.
If Campaign.IsReady == false and the within items exist the entry {'type": "error", "heading": "List"},
we could retrieve the List and calculate based on the recipient count a Thread.Sleep (List.RecipientsCount * xxxx) before we try again a Campaigns.SendChecklistAsync.

I'm just not sure if it's good to add a "blackbox delay" in a wrapper. Maybe as optional parameter? Campaign.SendAsync(campaignId, delayEnabled: true)

Stale issue message