Пример #1
0
        public string CreateTriggeredSendDefinition(string name, string customerKey, string description, string subject, string htmlBody)
        {
            try
            {
                DeleteSendClassification(customerKey);

                string emailCustomerKey = CreateEmail(name, customerKey, description, subject, htmlBody);

                //var sp = RetrieveSendProfile();
                //var dp = RetrieveDeliveryProfile();

                ET_SendClassification sendClassification = new ET_SendClassification();

                sendClassification.Name                            = name;
                sendClassification.CustomerKey                     = customerKey;
                sendClassification.SendClassificationType          = SendClassificationTypeEnum.Marketing;
                sendClassification.SendClassificationTypeSpecified = true;

                sendClassification.SenderProfile = new ET_SenderProfile()
                {
                    CustomerKey = "Default"
                };
                sendClassification.DeliveryProfile = new ET_DeliveryProfile()
                {
                    CustomerKey = "Default"
                };

                sendClassification.AuthStub = _etClient;
                PostReturn status = sendClassification.Post();

                string sendDefinitionCustomerKey = Guid.NewGuid().ToString();

                FuelSDK.ET_TriggeredSend postEmailSendDef = new FuelSDK.ET_TriggeredSend();
                postEmailSendDef.AuthStub    = _etClient;
                postEmailSendDef.Name        = name;
                postEmailSendDef.CustomerKey = sendDefinitionCustomerKey;
                postEmailSendDef.Description = description;

                postEmailSendDef.SendClassification  = (SendClassification)sendClassification; // new ET_SendClassification() { CustomerKey = sendClassification.CustomerKey };
                postEmailSendDef.TriggeredSendStatus = TriggeredSendStatusEnum.Active;

                FuelSDK.ET_Email email = new FuelSDK.ET_Email();
                email.Name        = name;
                email.AuthStub    = _etClient;
                email.CustomerKey = emailCustomerKey;

                postEmailSendDef.Email = email;

                PostReturn postResponse = postEmailSendDef.Post();

                if (postResponse.Status)
                {
                    return(sendDefinitionCustomerKey);
                }
                else
                {
                    return(string.Empty);
                }

                //return
                //    new PostReturnStatus()
                //    {
                //        Status = postResponse.Status.ToString(),
                //        Message = postResponse.Message.ToString(),
                //        Code = postResponse.Code.ToString(),
                //        ResultsLength = postResponse.Results.Length
                //};
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void Send()
        {
            ///////////////////////////////////////////////////////////////////
            //
            // setup the client stub, and add requisite
            // parameters to html body
            //
            ///////////////////////////////////////////////////////////////////

            ET_Client client = CreateClient();
            Body += "\r\nThis email was sent by:\r\n%%Member_Busname%%\r\n%%Member_Addr%%\r\n%%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%";

            ///////////////////////////////////////////////////////////////////
            //
            // use emails to setup the list of subscribers
            //
            ///////////////////////////////////////////////////////////////////

            List<ET_Subscriber> subscribers = new List<ET_Subscriber>();

            foreach (string recipient in To)
            {
                ET_Subscriber subscriber = new ET_Subscriber();
                subscriber.EmailAddress = recipient;
                subscriber.SubscriberKey = recipient;

                subscribers.Add(subscriber);
            }

            ///////////////////////////////////////////////////////////////////
            //
            // create email within ExactTarget email list
            //
            ///////////////////////////////////////////////////////////////////

            ET_Email email = new ET_Email();
            email.AuthStub = client;
            email.Name = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
            email.Subject = Subject;
            email.HTMLBody = Body.Replace("\r\n", "<br>");
            email.TextBody = Regex.Replace(Body, "<.*?>", string.Empty);
            email.EmailType = "html";

            PostReturn results = email.Post();

            ///////////////////////////////////////////////////////////////////
            //
            // create triggered email within ExactTarget triggered email list
            //
            ///////////////////////////////////////////////////////////////////

            ET_TriggeredSend create = new ET_TriggeredSend();
            create.AuthStub = client;
            create.Name = email.Name;
            create.AutoAddSubscribers = true;
            create.AutoAddSubscribersSpecified = true;
            create.List = new ET_List() { ID = 228 };
            create.CustomerKey = Convert.ToString(Guid.NewGuid());
            create.Email = new ET_Email() { ID = results.Results[0].NewID };
            create.SendClassification = new ET_SendClassification() { CustomerKey = "Default Commercial" };

            create.Post();

            ///////////////////////////////////////////////////////////////////
            //
            // patch triggered email (to set active)
            //
            ///////////////////////////////////////////////////////////////////

            ET_TriggeredSend update = new ET_TriggeredSend();
            update.AuthStub = client;
            update.CustomerKey = create.CustomerKey;
            update.TriggeredSendStatus = TriggeredSendStatusEnum.Active;

            update.Patch();

            ///////////////////////////////////////////////////////////////////
            //
            // send triggered email
            //
            ///////////////////////////////////////////////////////////////////

            ET_TriggeredSend send = new ET_TriggeredSend();
            send.AuthStub = client;
            send.CustomerKey = update.CustomerKey;
            send.Subscribers = subscribers.ToArray();

            send.Send();
        }
Пример #3
0
        static void TestET_Email(){
            ET_Client myclient = new ET_Client();
            string NameOfTestEmail = "CSharpSDKEmail";

            Console.WriteLine("--- Testing Email ---");
            Console.WriteLine("\n Retrieve All Email with GetMoreResults");
            ET_Email getAllEmail = new ET_Email();
            getAllEmail.AuthStub = myclient;
            getAllEmail.Props = new string[] { "ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Name","Folder","CategoryID","TextBody","Subject","IsActive","IsHTMLPaste","ClonedFromID","Status","EmailType","CharacterSet","HasDynamicSubjectLine","ContentCheckStatus","Client.PartnerClientKey","ContentAreas","CustomerKey" };
            GetReturn grAllEmail = getAllEmail.Get();

            Console.WriteLine("Get Status: " + grAllEmail.Status.ToString());
            Console.WriteLine("Message: " + grAllEmail.Message.ToString());
            Console.WriteLine("Code: " + grAllEmail.Code.ToString());
            Console.WriteLine("Results Length: " + grAllEmail.Results.Length);

            while (grAllEmail.MoreResults)
            {
                Console.WriteLine("\n Continue Retrieve All Email with GetMoreResults");
                grAllEmail = getAllEmail.GetMoreResults();
                Console.WriteLine("Get Status: " + grAllEmail.Status.ToString());
                Console.WriteLine("Message: " + grAllEmail.Message.ToString());
                Console.WriteLine("Code: " + grAllEmail.Code.ToString());
                Console.WriteLine("Results Length: " + grAllEmail.Results.Length);
            }

            Console.WriteLine("\n Create Email");            
            ET_Email postEmail = new ET_Email();
            postEmail.AuthStub = myclient;
            postEmail.Name = NameOfTestEmail;
            postEmail.CustomerKey = NameOfTestEmail;
            postEmail.Subject = "Created Using the Fuel SDK";
            postEmail.HTMLBody =  "<b>Some HTML Goes here</b>";	
            PostReturn postResponse = postEmail.Post();
            Console.WriteLine("Post Status: " + postResponse.Status.ToString());
            Console.WriteLine("Message: " + postResponse.Message.ToString());
            Console.WriteLine("Code: " + postResponse.Code.ToString());
            Console.WriteLine("Results Length: " + postResponse.Results.Length);

            if (postResponse.Status)
            {
                Console.WriteLine("\n Retrieve newly create Email");
                ET_Email getEmail = new ET_Email();
                getEmail.AuthStub = myclient;
                getEmail.Props = new string[] { "ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Name","Folder","CategoryID","HTMLBody","TextBody","Subject","IsActive","IsHTMLPaste","ClonedFromID","Status","EmailType","CharacterSet","HasDynamicSubjectLine","ContentCheckStatus","Client.PartnerClientKey","ContentAreas","CustomerKey" };
                getEmail.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestEmail } };
                GetReturn getResponse = getEmail.Get();
                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);
                foreach (ET_Email ResultEmail in getResponse.Results)
                {
                    Console.WriteLine("--ID: " + ResultEmail.ID + ", Name: " + ResultEmail.Name + ", HTMLBody: " + ResultEmail.HTMLBody);
                }

                Console.WriteLine("\n Update Email");
                ET_Email patchEmail = new ET_Email();
                patchEmail.CustomerKey = NameOfTestEmail;
                patchEmail.HTMLBody = "<b>Some HTML Goes here. NOW WITH NEW CONTENT</b>";
                patchEmail.AuthStub = myclient;
                FuelSDK.PatchReturn patchFR = patchEmail.Patch();
                Console.WriteLine("Patch Status: " + patchFR.Status.ToString());
                Console.WriteLine("Message: " + patchFR.Message.ToString());
                Console.WriteLine("Code: " + patchFR.Code.ToString());
                Console.WriteLine("Results Length: " + patchFR.Results.Length);

                Console.WriteLine("\n Retrieve updated Email");
                getEmail.Props = new string[] { "ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Name","Folder","CategoryID","HTMLBody","TextBody","Subject","IsActive","IsHTMLPaste","ClonedFromID","Status","EmailType","CharacterSet","HasDynamicSubjectLine","ContentCheckStatus","Client.PartnerClientKey","ContentAreas","CustomerKey" };
                getEmail.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestEmail } };
                getResponse = getEmail.Get();
                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);
                foreach (ET_Email ResultEmail in getResponse.Results)
                {
                    Console.WriteLine("--ID: " + ResultEmail.ID + ", Name: " + ResultEmail.Name + ", HTMLBody: " + ResultEmail.HTMLBody);
                }

                Console.WriteLine("\n Delete Email");
                ET_Email delEmail = new ET_Email();
                delEmail.CustomerKey = NameOfTestEmail;
                delEmail.AuthStub = myclient;
                DeleteReturn deleteResponse = delEmail.Delete();
                Console.WriteLine("Delete Status: " + deleteResponse.Status.ToString());
                Console.WriteLine("Message: " + deleteResponse.Message.ToString());
                Console.WriteLine("Code: " + deleteResponse.Code.ToString());
                Console.WriteLine("Results Length: " + deleteResponse.Results.Length);

                Console.WriteLine("\n Retrieve Email to confirm deletion");
                getEmail.Props = new string[] { "ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Name","Folder","CategoryID","HTMLBody","TextBody","Subject","IsActive","IsHTMLPaste","ClonedFromID","Status","EmailType","CharacterSet","HasDynamicSubjectLine","ContentCheckStatus","Client.PartnerClientKey","ContentAreas","CustomerKey" };
                getEmail.SearchFilter = new SimpleFilterPart() { Property = "CustomerKey", SimpleOperator = SimpleOperators.equals, Value = new String[] { NameOfTestEmail } };
                getResponse = getEmail.Get();
                Console.WriteLine("Get Status: " + getResponse.Status.ToString());
                Console.WriteLine("Message: " + getResponse.Message.ToString());
                Console.WriteLine("Code: " + getResponse.Code.ToString());
                Console.WriteLine("Results Length: " + getResponse.Results.Length);

                Console.WriteLine("\n Info Email");
                ET_Email EmailInfo = new ET_Email();
                EmailInfo.AuthStub = myclient;
                InfoReturn info = EmailInfo.Info();
                Console.WriteLine("Info Status: " + info.Status.ToString());
                Console.WriteLine("Message: " + info.Message.ToString());
                Console.WriteLine("Code: " + info.Code.ToString());
                Console.WriteLine("Results Length: " + info.Results.Length);
                foreach (ET_PropertyDefinition def in info.Results)
                {
                    Console.WriteLine("--Name: " + def.Name + ", IsRetrievable: " + def.IsRetrievable.ToString());
                }
            }
        }