/// <summary>
        /// Create a new campaign.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="campaign">Campign to be created</param>
        /// <returns>Returns a campaign.</returns>
        public EmailCampaign AddCampaign(string accessToken, string apiKey, EmailCampaign campaign)
        {
            EmailCampaign emailcampaign = null;
            string url = String.Concat(Config.Endpoints.BaseUrl, Config.Endpoints.Campaigns);
            string json = campaign.ToJSON();
            CUrlResponse response = RestClient.Post(url, accessToken, apiKey, json);
            if (response.HasData)
            {
                emailcampaign = response.Get<EmailCampaign>();
            }
            else if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }

            return emailcampaign;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create an EmailCampaign object from user inputs
        /// </summary>
        /// <returns></returns>
        private EmailCampaign CreateCampaignFromInputs()
        {
            EmailCampaign campaign = new EmailCampaign();

            #region General settings

            if (!string.IsNullOrWhiteSpace(txtCampaignName.Text))
            {
                campaign.Name = txtCampaignName.Text.Trim();
            }

            if (cbCampaignType.SelectedItem != null)
            {
                //campaign.TemplateType = GetCampaignType(cbCampaignType.SelectedItem as ItemInfo);
            }

            if (!string.IsNullOrWhiteSpace(txtSubject.Text))
            {
                campaign.Subject = txtSubject.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtFromName.Text))
            {
                campaign.FromName = txtFromName.Text.Trim();
            }

            if (cbFromEmail.SelectedIndex != null)
            {
                campaign.FromEmail = GetSelectedValue(cbFromEmail.SelectedItem as ItemInfo);
            }

            if (cbReplyToEmail.SelectedIndex != null)
            {
                campaign.ReplyToEmail = GetSelectedValue(cbReplyToEmail.SelectedItem as ItemInfo);
            }

            if (rbnHtml.Checked)
            {
                campaign.EmailContentFormat = CampaignEmailFormat.HTML;
            }
            else
            {
                campaign.EmailContentFormat = CampaignEmailFormat.XHTML;
            }

            if (!string.IsNullOrWhiteSpace(txtGreetingString.Text))
            {
                campaign.GreetingString = txtGreetingString.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtEmailContent.Text))
            {
                campaign.EmailContent = txtEmailContent.Text.Trim();
            }

            if (!string.IsNullOrWhiteSpace(txtContent.Text))
            {
                campaign.TextContent = txtContent.Text.Trim();
            }

            #endregion General settings

            #region Message footer settings

            //organization name is required for message footer section
            if (!string.IsNullOrWhiteSpace(txtOrganizationName.Text))
            {
                MessageFooter msgFooter = new MessageFooter();

                if (!string.IsNullOrWhiteSpace(txtOrganizationName.Text))
                {
                    msgFooter.OrganizationName = txtOrganizationName.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtAddressLine1.Text))
                {
                    msgFooter.AddressLine1 = txtAddressLine1.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtAddressLine2.Text))
                {
                    msgFooter.AddressLine2 = txtAddressLine2.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtAddressLine3.Text))
                {
                    msgFooter.AddressLine3 = txtAddressLine3.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtCity.Text))
                {
                    msgFooter.City = txtCity.Text.Trim();
                }

                if (!string.IsNullOrWhiteSpace(txtZip.Text))
                {
                    msgFooter.PostalCode = txtZip.Text.Trim();
                }

                if (cbCountry.SelectedItem != null)
                {
                    msgFooter.Country = GetSelectedValue(cbCountry.SelectedItem as ItemInfo);
                }
                if (cbState.SelectedItem != null)
                {
                    var state = cbState.SelectedItem as ItemInfo;
                    if (state != null)
                    {
                        msgFooter.State = state.Name;
                    }
                }


                if (chkIncludeForwardEmail.Checked)
                {
                    msgFooter.ForwardEmailLinkText = txtIncludeForwardEmail.Text.Trim();
                    msgFooter.IncludeForwardEmail = true;
                }

                if (chkIncludeSubscribeLink.Checked)
                {
                    msgFooter.SubscribeLinkText = txtIncludeSubscribeLink.Text.Trim();
                    msgFooter.IncludeSubscribeLink = true;
                }

                campaign.MessageFooter = msgFooter;
            }

            #endregion Message footer settings

            #region Contact lists settings

            List<SentContactList> lists = new List<SentContactList>();

            if (lstContactList.SelectedItems.Count > 0)
            {
                foreach (var item in lstContactList.SelectedItems)
                {
                    SentContactList contactList = new SentContactList() { 
                         Id  = GetSelectedValue(item as ItemInfo)
                    };

                    lists.Add(contactList);
                }
            }

            campaign.Lists = lists;

            #endregion Contact lists settings

            #region Schedule campaign settings

            if (rbnDraft.Checked)
            {
                campaign.Status = CampaignStatus.DRAFT;
            }
            else if (rbnSendNow.Checked)
            {
                campaign.Status = CampaignStatus.SENT;
            }
            else if (rbnScheduled.Checked)
            {
                campaign.Status = CampaignStatus.SCHEDULED;               
            }

            #endregion Schedule campaign settings

            return campaign;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update a specific email campaign.
        /// </summary>
        /// <param name="campaign">Campaign to be updated.</param>
        /// <returns>Returns a campaign.</returns>
        /// <exception cref="IllegalArgumentException">IllegalArgumentException</exception>
        public EmailCampaign UpdateCampaign(EmailCampaign campaign)
        {
            if (campaign == null)
            {
                throw new IllegalArgumentException(Config.Errors.EmailCampaignOrId);
            }

            return EmailCampaignService.UpdateCampaign(AccessToken, APIKey, campaign);
        }
Exemplo n.º 4
0
        public void LiveCampaignTrackingGetOpensTest()
        {
            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 ",
                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);

            DateTime schDate = DateTime.Now;
            Schedule schedule = cc.AddSchedule(camp.Id, new Schedule { ScheduledDate = schDate });
            Assert.IsNotNull(schedule);
            Assert.AreNotEqual(0, schedule.Id);
            Assert.IsNotNull(schedule.ScheduledDate);

            ResultSet<OpenActivity> result = cc.GetCampaignTrackingOpens(camp.Id, null, DateTime.Now.AddMonths(-1));

            Assert.IsNotNull(result);
        }
Exemplo n.º 5
0
        public void LiveCampaignTrackingGetSummaryTest()
        {
            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);

            TrackingSummary summary = cc.GetCampaignTrackingSummary(camp.Id);

            Assert.IsNotNull(summary);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        private EmailCampaign CreateTestCampaign()
        {
            var cc = new ConstantContactFactory(userServiceContext);
            var emailCampaignService = cc.CreateEmailCampaignService();
            var campaignScheduleService = cc.CreateCampaignScheduleService();

            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 ",
                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 = emailCampaignService.AddCampaign(camp);
            Assert.IsNotNull(camp);
            Assert.IsNotNull(camp.Id);

            DateTime schDate = DateTime.Now.AddDays(1);
            Schedule schedule = campaignScheduleService.AddSchedule(camp.Id, new Schedule { ScheduledDate = schDate });
            Assert.IsNotNull(schedule);
            Assert.AreNotEqual("", schedule.Id);
            Assert.IsNotNull(schedule.ScheduledDate);

            return camp;
        }
Exemplo n.º 8
0
        public void LiveUpdateEmailCampaignTest()
        {
            var cc = new ConstantContactFactory(userServiceContext);
            var emailCampignService = cc.CreateEmailCampaignService();

            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",
                    PostalCode = "02101",
                    State = "MA",
                    Country = "US",
                    IncludeForwardEmail = true,
                    ForwardEmailLinkText = "forward link",
                    IncludeSubscribeLink = true,
                    SubscribeLinkText = "subscribe link"
                }
                ,
                Lists = new List<SentContactList> { new SentContactList { Id = "1" } }
            };
            camp = emailCampignService.AddCampaign(camp);
            Assert.IsNotNull(camp);
            Assert.IsNotNull(camp.Id);

            camp.GreetingString = "Hi";
            var camp1 = emailCampignService.UpdateCampaign(camp);
            Assert.IsNotNull(camp1);
            Assert.AreEqual(camp.Id, camp1.Id);
            Assert.AreEqual(camp.GreetingString, camp1.GreetingString);
        }
        /// <summary>
        /// Update a specific email campaign.
        /// </summary>
        /// <param name="accessToken">Constant Contact OAuth2 access token.</param>
        /// <param name="apiKey">The API key for the application</param>
        /// <param name="campaign">Campaign to be updated.</param>
        /// <returns>Returns a campaign.</returns>
        public EmailCampaign UpdateCampaign(string accessToken, string apiKey, EmailCampaign campaign)
        {
            EmailCampaign emailCampaign = null;
            string url = String.Concat(Config.Endpoints.BaseUrl, String.Format(Config.Endpoints.Campaign, campaign.Id));
            // Invalidate data that are not supported by the update API procedure
            campaign.CreatedDate = null;
            campaign.TrackingSummary = null;
            campaign.ModifiedDate = null;
            campaign.IsVisibleInUI = null;
            // Convert to JSON string
            string json = campaign.ToJSON();
            CUrlResponse response = RestClient.Put(url, accessToken, apiKey, json);

            if (response.IsError)
            {
                throw new CtctException(response.GetErrorMessage());
            }

            if (response.HasData)
            {
                emailCampaign = response.Get<EmailCampaign>();
            }

            return emailCampaign;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Update a specific email campaign.
        /// </summary>
        /// <param name="campaign">Campaign to be updated.</param>
        /// <returns>Returns a campaign.</returns>
        public EmailCampaign UpdateCampaign(EmailCampaign campaign)
        {
            if (campaign == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.EmailCampaignOrId);
            }

            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, String.Format(Settings.Endpoints.Default.Campaign, campaign.Id));
            // Invalidate data that are not supported by the update API procedure
            campaign.CreatedDate = null;
            campaign.TrackingSummary = null;
            campaign.ModifiedDate = null;
            campaign.IsVisibleInUI = null;
            // Convert to JSON string
            string json = campaign.ToJSON();
            RawApiResponse response = RestClient.Put(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);
            try
            {
                var emailCampaign = response.Get<EmailCampaign>();
                return emailCampaign;
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a new campaign.
        /// </summary>
        /// <param name="campaign">Campign to be created</param>
        /// <returns>Returns a campaign.</returns>
        public EmailCampaign AddCampaign(EmailCampaign campaign)
        {
            if (campaign == null)
            {
                throw new IllegalArgumentException(CTCT.Resources.Errors.EmailCampaignOrId);
            }

            string url = String.Concat(Settings.Endpoints.Default.BaseUrl, Settings.Endpoints.Default.Campaigns);
            string json = campaign.ToJSON();
            RawApiResponse response = RestClient.Post(url, UserServiceContext.AccessToken, UserServiceContext.ApiKey, json);
            try
            {
                var emailcampaign = response.Get<EmailCampaign>();
                return emailcampaign;
            }
            catch (Exception ex)
            {
                throw new CtctException(ex.Message, ex);
            } 
        }
Exemplo n.º 12
0
        public void LiveUpdateFailedForScheduledCampaignTest()
        {
            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);

            DateTime schDate = DateTime.Now.AddMonths(1);
            Schedule schedule = cc.AddSchedule(camp.Id, new Schedule { ScheduledDate = schDate });
            Assert.IsNotNull(schedule);
            Assert.AreNotEqual("", schedule.Id);
            Assert.IsNotNull(schedule.ScheduledDate);

            camp.GreetingName = GreetingName.FIRST_AND_LAST_NAME;

            var updatedCampaign = cc.UpdateCampaign(camp);
            Assert.IsNull(updatedCampaign);
        }