Sending a test email

Dec 3, 2012 at 6:46 AM
Edited Dec 3, 2012 at 6:48 AM

Hi there

I am currently putting together some code to send a Mailchimp campaign from within the admin area of Umbraco.

All is (or was) proceeding nicely until I have tried to get a test email to send.

I am getting an error back of 

System.Collections.Generic.List`1[PerceptiveMCAPI.Types.Api_Error]

To me this relates to the types which is an EnumValues.campaignSendTest_send_type

My code is:

 

public static void sendTestEmail(string campaignID, List<string> test_emails, string send_type)
{
campaignSendTestInput campaignSendTestInp = new campaignSendTestInput(campaignID,test_emails,sendType(send_type));
campaignSendTest campaignSendTst = new campaignSendTest(campaignSendTestInp);
campaignSendTestOutput campaignTestOutput = new campaignSendTestOutput(campaignSendTestInp);

//temporary method to send email of error
genericHelper.SendEmail("emailaddy", "emailaddy", "No Reply", "MailChimp", campaignTestOutput.api_ErrorMessages.ToString());
}
private static EnumValues.campaignSendTest_send_type sendType(string send_type)
{
if (send_type == "html") {
return EnumValues.campaignSendTest_send_type.html;
} else if (send_type == "text") {
return EnumValues.campaignSendTest_send_type.text;
} else {
return EnumValues.campaignSendTest_send_type.NotSpecified;
}
}

Is anyone able to assist in shedding some light on the way to resolve ?

Thanks, Nigel

Dec 4, 2012 at 7:58 AM
Edited Dec 4, 2012 at 7:59 AM

OK - have now succeeded in sending a test campaign email.

The working code is below

The issue seemed to be in the campaignTestOutput

public static void sendTestEmail(string campaignID, List<string> test_emails, string send_type)
{
campaignSendTestParms campaignTestParms = new campaignSendTestParms();
campaignTestParms.apikey = MCAPISettings.default_apikey;
campaignTestParms.cid = campaignID;
campaignTestParms.test_emails = test_emails;
campaignTestParms.send_type = sendType(send_type);
campaignSendTestInput campaignSendTestInp = new campaignSendTestInput(campaignTestParms);
campaignSendTest campaignSendTst = new campaignSendTest(campaignSendTestInp);
string output = campaignSendTst.Execute().result.ToString(); }

public static EnumValues.campaignSendTest_send_type sendType(string send_type)
{
if (send_type == "html")
{
return EnumValues.campaignSendTest_send_type.html;
}
else if (send_type == "text")
{
return EnumValues.campaignSendTest_send_type.text;
}
else
{
return EnumValues.campaignSendTest_send_type.NotSpecified;
}

}

 

Hope this helps someone.

Nigel