/// <summary> /// Send a test send of a campaign. /// </summary> /// <param name="accessToken">Constant Contact OAuth2 access token.</param> /// <param name="apiKey">The API key for the application</param> /// <param name="campaignId">Id of campaign to send test of.</param> /// <param name="testSend">Test send details.</param> /// <returns>Returns the sent test object.</returns> public TestSend SendTest(string accessToken, string apiKey, string campaignId, TestSend testSend) { TestSend test = null; string url = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.CampaignTestSends, campaignId)); string json = testSend.ToJSON(); CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json); if (response.IsError) { throw new CtctException(response.GetErrorMessage()); } if (response.HasData) { test = Component.FromJSON<TestSend>(response.Body); } return test; }
public void LiveEmailCampaignTestSendTest() { var cc = new ConstantContact(ApiKey, AccessToken); var camp = new EmailCampaign { EmailContent = "<html><body>EMAIL CONTENT.</body></html>", Subject = "campaign subject", FromName = "my company", FromEmail = CustomerEmail, ReplyToEmail = CustomerEmail, Name = "campaign_" + DateTime.Now.ToString("yyMMddHHmmss"), TextContent = "email campaign text content", GreetingString = "Dear ", //TemplateType = TemplateType.CUSTOM, Status = CampaignStatus.DRAFT, EmailContentFormat = CampaignEmailFormat.HTML, StyleSheet = "", MessageFooter = new MessageFooter { OrganizationName = "my organization", AddressLine1 = "123 Mapple Street", AddressLine2 = "Suite 1", AddressLine3 = "", City = "Boston", State = "MA", PostalCode = "02101", Country = "US", IncludeForwardEmail = true, ForwardEmailLinkText = "forward link", IncludeSubscribeLink = true, SubscribeLinkText = "subscribe link" } , Lists = new List<SentContactList> { new SentContactList { Id = "1" } } }; camp = cc.AddCampaign(camp); Assert.IsNotNull(camp); Assert.IsNotNull(camp.Id); var test = new TestSend { Format = EmailFormat.HTML_AND_TEXT.ToString(), PersonalMessage = "This is a test send of the email campaign message.", EmailAddresses = new List<string> { CustomerEmail } }; var testSend = cc.SendTest(camp.Id, test); Assert.IsNotNull(testSend); Assert.AreEqual(test.Format, testSend.Format); }
/// <summary> /// Send a test send of a campaign. /// </summary> /// <param name="campaignId">Id of campaign to send test of.</param> /// <param name="testSend">Test send details.</param> /// <returns>Returns the sent object.</returns> /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception> public TestSend SendTest(string campaignId, TestSend testSend) { if (string.IsNullOrEmpty(campaignId) || testSend == null) { throw new IllegalArgumentException(Config.Errors.ScheduleOrId); } return CampaignScheduleService.SendTest(AccessToken, APIKey, campaignId, testSend); }
/// <summary> /// Send a test send of a campaign. /// </summary> /// <param name="campaignId">Id of campaign to send test of.</param> /// <param name="testSend">Test send details.</param> /// <returns>Returns the sent test object.</returns> public TestSend SendTest(string campaignId, TestSend testSend) { if (string.IsNullOrEmpty(campaignId) || testSend == null) { throw new IllegalArgumentException(CTCT.Resources.Errors.ScheduleOrId); } string url = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.CampaignTestSends, campaignId)); string json = testSend.ToJSON(); RawApiResponse response = RestClient.Post(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json); try { var test = response.Get<TestSend>(); return test; } catch (Exception ex) { throw new CtctException(ex.Message, ex); } }