如何使用ASP.Net在MailChimp中创建一个活动

Ani*_*nil 5 c# asp.net mailchimp

我需要立即制作并发送广告系列MailChimp.com.我用于此目的. C# wrapper Percepective MCAPI.dll

来自MailChimp API,很明显我们不能列出但可以创建广告系列.我试过代码但是campaignID is retured null; 没有异常抛出至少.我确实设置了campaigntype to Auto.

这是我的代码片段:

try
{
     string apiKey = "api-us2";   // API KEY is valid
     string emailAddress = "ravinderpal.singh@abc.net";
     listsForEmailInput lstForEmailInput = new listsForEmailInput(apiKey, emailAddress);
     listsForEmail cmd = new listsForEmail(lstForEmailInput);
     listsForEmailOutput lstEmailOutPut = cmd.Execute();

     List lstResults = lstEmailOutPut.result;
     string listID = lstResults[0]; // Got Precraeted List ID( Valid Confirmed )

     Console.WriteLine("\n" + listID);                


     // compaign Create
     campaignCreateOptions campaignCreateOpt = new campaignCreateOptions();
     campaignCreateOpt.list_id = listID;
     campaignCreateOpt.subject = " New Campaign from dev_Anil";
     campaignCreateOpt.from_email = "anil.k@abc.net";
     campaignCreateOpt.from_name = "anil";

     Dictionary content = new Dictionary();
     content.Add("html", "Helloaasdsa");
     content.Add("text", "Hi all !! this is dev_anil");
     content.Add("url", "");
     content.Add("archive", "");

     campaignSegmentOptions csOptions = new campaignSegmentOptions();
     csOptions.match = "any";  // Could not set Condition -- need help for this

     // Need to set a Dictionary typeOptions because null is not supported
     Dictionary typeOptions = new Dictionary();

     campaignCreateParms campaignCreateParms = new campaignCreateParms(apiKey, EnumValues.campaign_type.auto, campaignCreateOpt, content, csOptions, typeOptions);
     campaignCreateInput campaignCreateInput = new campaignCreateInput(campaignCreateParms);
     campaignCreate campaignCreate = new campaignCreate(campaignCreateInput);
     campaignCreateOutput ccOutput = campaignCreate.Execute(campaignCreateInput);
     string abc = ccOutput.result;   // This comes out to null

}
 catch(Exception ee)
{
     Console.WriteLine("\n\n Exception :" + ee.Message);  // no exception
}

谁能告诉我正确的方向以及代码有什么问题.

任何帮助将非常感激.

谢谢.

Ani*_*nil 2

我解决了这个问题,这里是代码作为解决方案。这里的 listID 是您在 Mailchimp 帐户中预先创建的列表 ID。

私有无效CreateCampaignAndSend(字符串apiKey,字符串listID)
{
            Int32 模板ID = 100;
            字符串活动ID = string.Empty;

// compaign Create Options campaignCreateOptions campaignCreateOpt = new campaignCreateOptions(); campaignCreateOpt.list_id = listID; campaignCreateOpt.subject = "subject"; campaignCreateOpt.from_email = "abc@xyz.com"; campaignCreateOpt.from_name = "abc"; campaignCreateOpt.template_id = TemplateID; // Content Dictionary<string, string> content = new Dictionary<string, string>(); content.Add("html_ArticleTitle1", "ArticleTitle1"); content.Add("html_ArticleTitle2","ArticleTitle2"); content.Add("html_ArticleTitle3", "ArticleTitle3"); content.Add("html_Article1", "Article1"); content.Add("html_Article2", "Article2"); // Conditions List<campaignSegmentCondition> csCondition = new List<campaignSegmentCondition>(); campaignSegmentCondition csC = new campaignSegmentCondition(); csC.field = "interests-" + 123; // where 123 is the Grouping Id from listInterestGroupings() csC.op = "all"; csC.value = ""; csCondition.Add(csC); // Options campaignSegmentOptions csOptions = new campaignSegmentOptions(); csOptions.match = "all"; // Type Options Dictionary<string, string> typeOptions = new Dictionary<string, string>(); typeOptions.Add("offset-units", "days"); typeOptions.Add("offset-time", "0"); typeOptions.Add("offset-dir", "after"); // Create Campaigns campaignCreate campaignCreate = new campaignCreate(new campaignCreateInput(apiKey, EnumValues.campaign_type.plaintext, campaignCreateOpt, content, csOptions, typeOptions)); campaignCreateOutput ccOutput = campaignCreate.Execute(); List<Api_Error> error = ccOutput.api_ErrorMessages; // Catching API Errors if (error.Count <= 0) { campaignID = ccOutput.result; } else { foreach (Api_Error ae in error) { Console.WriteLine("\n ERROR Creating Campaign : ERRORCODE\t:" + ae.code + "\t ERROR\t:" + ae.error); } } }

Run Code Online (Sandbox Code Playgroud)