Пример #1
0
        void GetRecipients()
        {
            Campaign campaign = new Campaign(campaignID);

            try
            {
                List<CampaignRecipient> recipients = new List<CampaignRecipient>();
                PagedCollection<CampaignRecipient> firstPage = campaign.Recipients(1, 50, "email", "ASC");
                recipients.AddRange(firstPage.Results);

                if (firstPage.NumberOfPages > 1)
                    for (int pageNumber = 2; pageNumber <= firstPage.NumberOfPages; pageNumber++)
                    {
                        PagedCollection<CampaignRecipient> subsequentPage = campaign.Recipients(pageNumber, 50, "email", "ASC");
                        recipients.AddRange(subsequentPage.Results);
                    }

                foreach (CampaignRecipient recipient in recipients)
                    Console.WriteLine(recipient.EmailAddress);
            }
            catch (CreatesendException ex)
            {
                ErrorResult error = (ErrorResult)ex.Data["ErrorResult"];
                Console.WriteLine(error.Code);
                Console.WriteLine(error.Message);
            }
            catch (Exception ex)
            {
                // handle some other failure
            }
        }
Пример #2
0
        public string SendCampaign(CampaignMonitorRequest request)
        {
            string Id = string.Empty;

            try
            {
                AuthenticationDetails auth    = new ApiKeyAuthenticationDetails(request.ApiKey);
                List <string>         listIDs = new List <string> {
                    request.ListId
                };
                List <string> segmentIDs = new List <string> {
                    request.SegmentIDs
                };

                TemplateContent templateContent = new TemplateContent();

                string campaignID = createsend_dotnet.Campaign.CreateFromTemplate(
                    auth,
                    request.ClientID,
                    request.Subject,
                    request.Name,
                    request.FromName + "-" + DateTime.Now.ToString("MMddyyyyhhmm"),
                    request.FromEmail,
                    request.FromEmail,
                    listIDs,
                    segmentIDs,
                    CreateTemplateFromCosmosDocument(auth, request.ClientID, request.campaign),
                    templateContent);

                createsend_dotnet.Campaign campaignMonitorCampaign = new createsend_dotnet.Campaign(auth, campaignID);
                campaignMonitorCampaign.Send(request.FromEmail);
                Id = campaignID;
            }
            catch (Exception e)
            {
                var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name);
                telemetria.Critical(messageException);
            }
            return(Id);
        }
Пример #3
0
        public void GetEmailClientUsage()
        {
            Campaign campaign = new Campaign(auth, campaignID);

            try
            {
                var usage = campaign.EmailClientUsage();
                foreach (EmailClient client in usage)
                    Console.WriteLine("{0} ({1}): used by %{2} ({3} subscribers)",
                        client.Client, client.Version, client.Percentage, client.Subscribers);
            }
            catch (CreatesendException ex)
            {
                ErrorResult error = (ErrorResult)ex.Data["ErrorResult"];
                Console.WriteLine(error.Code);
                Console.WriteLine(error.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #4
0
        public string CreateCampaignMonitor(string idCampaign)
        {
            var    campaign  = GetCampaignById(idCampaign);
            var    product   = GetProductByIdProduct(campaign.PRODUCT.IdProduct);
            string idList    = null;
            string apiKey    = null;
            string clientID  = null;
            string subject   = "";
            string fromEmail = "";
            string fromName  = "";
            string segment   = "";


            if (product.PRODUCT_SETTINGS != null && product.PRODUCT_SETTINGS.Any())
            {
                foreach (var item in product.PRODUCT_SETTINGS)
                {
                    apiKey   = item.SettingName.Equals("campaignMonitorApiToken") ? item.SettingValue : apiKey;
                    idList   = item.SettingName.Equals("campaignMonitorList") ? item.SettingValue : idList;
                    clientID = item.SettingName.Equals("campaignMonitorClient") ? item.SettingValue : clientID;
                    segment  = item.SettingName.Equals("campaignMonitorSegment") ? item.SettingValue : segment;
                }
            }

            if (campaign.CAMPAIGN_SETTINGS != null && campaign.CAMPAIGN_SETTINGS.Any())
            {
                foreach (var setting in campaign.CAMPAIGN_SETTINGS)
                {
                    subject   = setting.SettingName.Equals("campaignMonitorSubject") ? setting.SettingValue : subject;
                    fromName  = setting.SettingName.Equals("campaignMonitorFromName") ? setting.SettingValue : fromName;
                    fromEmail = setting.SettingName.Equals("campaignMonitorFromEmail") ? setting.SettingValue : fromEmail;
                }
            }

            try
            {
                AuthenticationDetails auth    = new ApiKeyAuthenticationDetails(apiKey);
                List <string>         listIDs = new List <string> {
                    idList
                };
                List <string> segmentIDs = new List <string> {
                    segment
                };

                TemplateContent templateContent = new TemplateContent();

                string campaignID = createsend_dotnet.Campaign.CreateFromTemplate(
                    auth,
                    clientID,
                    subject,
                    campaign.Name,
                    fromName + "-" + DateTime.Now.ToString("MMddyyyyhhmm"),
                    fromEmail,
                    fromEmail,
                    listIDs,
                    segmentIDs,
                    CreateTemplate(auth, clientID, campaign),
                    templateContent);

                createsend_dotnet.Campaign campaignMonitorCampaign = new createsend_dotnet.Campaign(auth, campaignID);
                campaignMonitorCampaign.Send(fromEmail);
                return(campaignID);
            }
            catch (Exception e)
            {
                var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name);
                telemetria.Critical(messageException);
            }

            return(null);
        }