Exemple #1
0
        public CampaignCreator(MailworxWebServiceAgent serviceAgent, SecurityContext securityContext)
        {
            if (serviceAgent == null)
            {
                throw new ArgumentNullException(nameof(serviceAgent), "serviceAgent must not be null!");
            }
            if (securityContext == null)
            {
                throw new ArgumentNullException(nameof(securityContext), "securityContext must not be null!");
            }

            this.serviceAgent    = serviceAgent;
            this.securityContext = securityContext;
        }
        public SubscriberImport(MailworxWebServiceAgent serviceAgent, SecurityContext securityContext)
        {
            if (serviceAgent == null)
            {
                throw new ArgumentNullException(nameof(serviceAgent), "serviceAgent must not be null!");
            }
            if (securityContext == null)
            {
                throw new ArgumentNullException(nameof(securityContext), "securityContext must not be null!");
            }

            this.serviceAgent    = serviceAgent;
            this.securityContext = securityContext;
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // ### GENERAL ###

            // This is the agent which will be used as connection to the mailworx webservice.
            MailworxWebServiceAgent agent = new MailworxWebServiceAgent
            {
                // The url to the webservice.
                Url = "http://sys.mailworx.info/services/serviceagent.asmx"
            };

            // Set  the login data.
            SecurityContext context = GetSecurityContext();

            // ### GENERAL ###



            // ### STEP 1 : IMPORT ###
            // Here we use a helper class in order to do all the necessary import steps.
            SubscriberImport import = new SubscriberImport(agent, context);

            // The key is the id of the profile where the subscribers have been imported to.
            // The value is a list of ids of the imported subscribers.
            KeyValuePair <Guid, List <Guid> > importedData = import.ImportSubscribers();

            // ### STEP 1 : IMPORT ###



            // If some data where imported....
            if (importedData.Value != null && importedData.Value.Count > 0)
            {
                // ### STEP 2 : CREATE CAMPAIGN ###

                // Here we use another helper class in order to do all the necessary steps for creating a campaign.
                CampaignCreator campaignCreator = new CampaignCreator(agent, context);

                // The key is the id of the template.
                // The value is the id of the campaign.
                KeyValuePair <Guid, Guid> data = campaignCreator.CreateCampaign(importedData.Key);

                // ### STEP 2 : CREATE CAMPAIGN ###



                // If a campaign was returned we can add the sections.
                if (data.Key != Guid.Empty && data.Value != Guid.Empty)
                {
                    // ### STEP 3 : ADD SECTIONS TO CAMPAIGN ###

                    // Here we use another helper class in order to do all the necessary steps for adding sections to the campaign.
                    SectionCreator sectionCreator = new SectionCreator(agent, context);

                    // Send the campaign, if all sections have been created.
                    if (sectionCreator.GenerateSection(data.Value, data.Key))
                    {
                        // ### STEP 3 : ADD SECTIONS TO CAMPAIGN ###



                        // ### STEP 4 : SEND CAMPAIGN ###

                        SendCampaignRequest sendCampaignRequest = new SendCampaignRequest()
                        {
                            CampaignId      = data.Key,
                            IgnoreCulture   = false,                           // Send the campaign only to subscribers with the same language as the campaign
                            SecurityContext = context,
                            SendType        = CampaignSendType.Manual,
                            Language        = "EN",
                            // If the SendType is set to Manual, ManualSendSettings are needed
                            // If the SendType is set to ABSplit, ABSplitTestSendSettings are needed
                            Settings = new ManualSendSettings()
                            {
                                SendTime = DateTime.Now
                            },
                            UseIRated = false,                             // Here is some more info about iRated http://www.mailworx.info/en/irated-technology
                            UseRTR    = true
                        };

                        // Send the campaign
                        SendCampaignResponse sendCampaignResponse = agent.SendCampaign(sendCampaignRequest);

                        // ### STEP 4 : SEND CAMPAIGN ###



                        if (sendCampaignResponse == null)
                        {
                            Console.WriteLine("Something went wrong");
                        }
                        else
                        {
                            Console.WriteLine(string.Format("Effective subscribers: {0}", sendCampaignResponse.RecipientsEffective));
                        }
                    }
                }
            }

            Console.ReadLine();
        }