private static TriggeredSendDefinition GetSendDefinition(string strGUID, int etEmailId, string toEmail, string emailName)
		{
			//Create TriggeredSendDefinition object [Messages > Email > Triggered]
			TriggeredSendDefinition tsd = new TriggeredSendDefinition();
			//tsd.Email.HTMLBody
			tsd.Name = strGUID;//required
			tsd.CustomerKey = strGUID;//recommended or the application will assign a number
			tsd.Description = emailName + " to " + toEmail;//recommended or the Description will default to the Name

			//Set to delivery both Text and HTML versions.
			tsd.IsMultipart = true;//recommended as a best practice
			tsd.IsMultipartSpecified = true;//required

			//Set to track the links found in the email
			tsd.IsWrapped = true;//recommended to take advantage of ExactTarget's tracking
			tsd.IsWrappedSpecified = true;//required

			//Create Email object to refer to pre-create Email
			Email em = new Email();
			em.ID = etEmailId;
			//em.ID = 620046;//required //Available in the ET UI [Content > My Emails > Properties]
			em.IDSpecified = true;//required

			//Apply Email object to the TriggeredSendDefinition object
			tsd.Email = em;//required
			tsd.Email.IsHTMLPaste = true;

			//Create SendClassification
			tsd.SendClassification = new SendClassification();
			// tsd.SendClassification.CustomerKey = "201";//required //Available in the ET UI [Admin > Send Management > Send Classifications > Edit Item > External Key]
			tsd.SendClassification.CustomerKey = ConfigurationManager.AppSettings["ExactTargetCustomerKey"];
			return tsd;
		}
        public void Trigger(ExactTargetTriggeredEmail exactTargetTriggeredEmail, RequestQueueing requestQueueing = RequestQueueing.No, Priority priority = Priority.Normal)
        {
            var clientId = _config.ClientId;
            var client = SoapClientFactory.Manufacture(_config);

            var subscriber = new Subscriber
            {
                EmailAddress = exactTargetTriggeredEmail.EmailAddress,
                SubscriberKey = exactTargetTriggeredEmail.SubscriberKey ?? exactTargetTriggeredEmail.EmailAddress,
                Attributes =
                    exactTargetTriggeredEmail.ReplacementValues.Select(value => new Attribute
                    {
                        Name = value.Key,
                        Value = value.Value
                    }).ToArray()
            };

            // Add sender information if specified. This will send the email with FromAddress in the sender field.
            // Official doco here under the section "Determining the From Information at Send Time":
            // https://help.exacttarget.com/en/technical_library/web_service_guide/triggered_email_scenario_guide_for_developers/#Determining_the_From_Information_at_Send_Time
            if (!string.IsNullOrEmpty(exactTargetTriggeredEmail.FromAddress) && !string.IsNullOrEmpty(exactTargetTriggeredEmail.FromName))
            {
                subscriber.Owner = new Owner()
                {
                    FromAddress = exactTargetTriggeredEmail.FromAddress,
                    FromName = exactTargetTriggeredEmail.FromName
                };
            }

            var subscribers = new List<Subscriber> { subscriber };

            var tsd = new TriggeredSendDefinition
            {
                Client = clientId.HasValue ? new ClientID { ID = clientId.Value, IDSpecified = true } : null,
                CustomerKey = exactTargetTriggeredEmail.ExternalKey
            };

            var ts = new TriggeredSend
            {
                Client = clientId.HasValue ? new ClientID { ID = clientId.Value, IDSpecified = true } : null,
                TriggeredSendDefinition = tsd,
                Subscribers = subscribers.ToArray()
            };

            var co = new CreateOptions
            {
                RequestType = requestQueueing == RequestQueueing.No ? RequestType.Synchronous : RequestType.Asynchronous,
                RequestTypeSpecified = true,
                QueuePriority = priority == Priority.High ? ExactTargetApi.Priority.High : ExactTargetApi.Priority.Medium,
                QueuePrioritySpecified = true
            };

            string requestId, status;
            var result = client.Create(
                co,
                new APIObject[] { ts },
                out requestId, out status);

            ExactTargetResultChecker.CheckResult(result.FirstOrDefault()); //we expect only one result because we've sent only one APIObject
        }
        public static void CreateTriggeredSend(SoapClient soapClient,
                                               string iTriggeredSendCustomerKey,
                                               string iEmailAddress,
                                               string iFirstName,
                                               string iLastName)
        {
            TriggeredSend           ts  = new TriggeredSend();
            TriggeredSendDefinition tsd = new TriggeredSendDefinition();

            tsd.CustomerKey            = iTriggeredSendCustomerKey;
            ts.TriggeredSendDefinition = tsd;

            Subscriber sub = new Subscriber();

            sub.EmailAddress  = iEmailAddress;
            sub.SubscriberKey = iEmailAddress;

            ExactTargetSOAPAPI.Attribute firstName = new ExactTargetSOAPAPI.Attribute();
            firstName.Name  = "First Name";
            firstName.Value = iFirstName;

            ExactTargetSOAPAPI.Attribute lastName = new ExactTargetSOAPAPI.Attribute();
            lastName.Name  = "Last Name";
            lastName.Value = iLastName;

            sub.Attributes = new ExactTargetSOAPAPI.Attribute[] { firstName, lastName };

            ts.Subscribers = new Subscriber[] { sub };

            string sStatus    = "";
            string sRequestId = "";

            CreateResult[] aoResults =
                soapClient.Create(new CreateOptions(), new APIObject[] { ts }, out sRequestId, out sStatus);

            Console.WriteLine("Status: " + sStatus);
            Console.WriteLine("Request ID: " + sRequestId);
            foreach (TriggeredSendCreateResult tscr in aoResults)
            {
                if (tscr.SubscriberFailures != null)
                {
                    foreach (SubscriberResult sr in tscr.SubscriberFailures)
                    {
                        Console.WriteLine("ErrorCode: " + sr.ErrorCode);
                        Console.WriteLine("ErrorDescription: " + sr.ErrorDescription);
                    }
                }
            }
        }
        public static void CreateTriggeredSend(SoapClient soapClient, 
            string iTriggeredSendCustomerKey, 
            string iEmailAddress, 
            string iFirstName, 
            string iLastName)
        {
            TriggeredSend ts = new TriggeredSend();
            TriggeredSendDefinition tsd = new TriggeredSendDefinition();
            tsd.CustomerKey = iTriggeredSendCustomerKey;
            ts.TriggeredSendDefinition = tsd;

            Subscriber sub = new Subscriber();
            sub.EmailAddress = iEmailAddress;
            sub.SubscriberKey = iEmailAddress;

            ExactTargetSOAPAPI.Attribute firstName = new ExactTargetSOAPAPI.Attribute();
            firstName.Name = "First Name";
            firstName.Value = iFirstName;

            ExactTargetSOAPAPI.Attribute lastName = new ExactTargetSOAPAPI.Attribute();
            lastName.Name = "Last Name";
            lastName.Value = iLastName;

            sub.Attributes = new ExactTargetSOAPAPI.Attribute[] { firstName, lastName };

            ts.Subscribers = new Subscriber[] { sub };

            string sStatus = "";
            string sRequestId = "";

            CreateResult[] aoResults =
                soapClient.Create(new CreateOptions(), new APIObject[] { ts }, out sRequestId, out sStatus);

            Console.WriteLine("Status: " + sStatus);
            Console.WriteLine("Request ID: " + sRequestId);
            foreach (TriggeredSendCreateResult tscr in aoResults)
            {
                if (tscr.SubscriberFailures != null)
                {
                    foreach (SubscriberResult sr in tscr.SubscriberFailures)
                    {
                        Console.WriteLine("ErrorCode: " + sr.ErrorCode);
                        Console.WriteLine("ErrorDescription: " + sr.ErrorDescription);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void TriggerCustom(TriggeredSendDataModel exactTargetTriggeredEmail, List <Subscriber> lst, RequestQueueing requestQueueing = RequestQueueing.No, Utlities.Priority priority = Utlities.Priority.Normal)
        {
            var clientId = _config.ClientId;
            var client   = SoapClientFactory.Manufacture(_config);

            var tsd = new TriggeredSendDefinition
            {
                Client = clientId.HasValue ? new ClientID {
                    ID = clientId.Value, IDSpecified = true
                } : null,
                CustomerKey = exactTargetTriggeredEmail.TriggerSendDefinitionExternalKey,
            };

            var ts = new TriggeredSend
            {
                Client = clientId.HasValue ? new ClientID {
                    ID = clientId.Value, IDSpecified = true
                } : null,
                TriggeredSendDefinition = tsd,
                Subscribers             = lst.ToArray(),
            };

            var co = new CreateOptions
            {
                RequestType            = requestQueueing == RequestQueueing.No ? RequestType.Synchronous : RequestType.Asynchronous,
                RequestTypeSpecified   = true,
                QueuePriority          = priority == Utlities.Priority.High ? ETService.Priority.High : ETService.Priority.Medium,
                QueuePrioritySpecified = true
            };

            string requestId, status;
            var    result = client.Create(
                co,
                new APIObject[] { ts },
                out requestId, out status);

            ExactTargetResultChecker.CheckResult(result.FirstOrDefault()); //we expect only one result because we've sent only one APIObject
        }
		private static string GetCreateResult(ref SoapClient client, TriggeredSendDefinition tsd, ref StringBuilder sbReturnString)
		{
			string cRequestID = String.Empty;
			string cStatus = String.Empty;

			try
			{
				//Call the Create method on the TriggeredSendDefinition object
				CreateResult[] cResults = client.Create(new CreateOptions(), new APIObject[] { tsd }, out cRequestID, out cStatus);

				Log.Info("[EXACTTARGET] Overall Create Status: " + cStatus, "");
				Log.Info("[EXACTTARGET] Number of Results: " + cResults.Length, "");
				sbReturnString.Append("[EXACTTARGET] Overall Create Status: " + cStatus).AppendLine();
				sbReturnString.Append("[EXACTTARGET] Number of Results: " + cResults.Length).AppendLine();


				////Display Results
				//lblMessage.Text += "Overall Create Status: " + cStatus;
				//lblMessage.Text += "<br/>";
				//lblMessage.Text += "Number of Results: " + cResults.Length;
				//lblMessage.Text += "<br/>";

				//Loop through each object returned and display the StatusMessage
				foreach (CreateResult cr in cResults)
				{
					Log.Info("[EXACTTARGET] Status Message: " + cr.StatusMessage, "");
					sbReturnString.Append("[EXACTTARGET] Status Message: " + cr.StatusMessage).AppendLine();

					//lblMessage.Text += "Status Message: " + cr.StatusMessage;
					//lblMessage.Text += "<br/>";
				}
			}
			catch (Exception exCreate)
			{
				//Set Message
				Log.Error("[EXACTTARGET] CREATE TSD ERROR: " + exCreate.Message.ToString(), exCreate, "something went wrong");
				//lblMessage.Text += "<br/><br/>CREATE TSD ERROR:<br/>" + exCreate.Message;
				// sbReturnString.Append("[EXACTTARGET] CREATE TSD ERROR: " + exCreate.Message.ToString()).AppendLine();
				throw;
			}

			return cStatus;
		}
		private static void SendEmail(ref SoapClient client, TriggeredSendDefinition tsd, ref StringBuilder sbReturnString, Subscriber newSub)
		{
			TriggeredSend ts = new TriggeredSend();
			ts.TriggeredSendDefinition = tsd;
			ts.Subscribers = new Subscriber[] { newSub };

			string tsRequestID = "";
			string tsStatus = "";

			try
			{
				//Call the Create method on the TriggeredSend object
				CreateResult[] tsResults = client.Create(new CreateOptions(), new APIObject[] { ts }, out tsRequestID, out tsStatus);

				//Display Results
				Log.Info("[EXACTTARGET] Overall Create Status: " + tsResults, "");
				Log.Info("[EXACTTARGET] Number of Results: " + tsResults.Length, "");
				sbReturnString.Append("<br />[EXACTTARGET] Overall Create Status: " + tsResults).AppendLine();
				sbReturnString.Append("<br />[EXACTTARGET] Number of Results: " + tsResults.Length).AppendLine();
				//lblMessage.Text += "Overall Update Status: " + tsStatus;
				//lblMessage.Text += "<br/>";
				//lblMessage.Text += "Number of Results: " + tsResults.Length;
				//lblMessage.Text += "<br/>";

				//Loop through each object returned and display the StatusMessage
				foreach (TriggeredSendCreateResult tscr in tsResults)
				{
					Log.Info("[EXACTTARGET] Status Message: " + tscr.StatusMessage.ToString(), "");
					sbReturnString.Append("<br />[EXACTTARGET] Status Message: " + tscr.StatusMessage).AppendLine();

                    if (tscr.SubscriberFailures != null)
                    {
                        sbReturnString.Append("<br/>[EXACTTARGET] Subscriber failures: <br/>");

                        foreach (SubscriberResult sr in tscr.SubscriberFailures)
                        {
                            Log.Info(String.Format("[EXACTTARGET] Subscriber failure : ({0}) {1}", sr.ErrorCode, sr.ErrorDescription), "");
                            sbReturnString.Append("<br/>[EXACTTARGET] ErrorDescription: " + sr.ErrorDescription);
                            sbReturnString.Append("<br/>[EXACTTARGET] Error Code: " + sr.ErrorCode + "<br />");
                        }
                    }
				}
			}
			catch (Exception exCreate)
			{

				Log.Error("<br />[EXACTTARGET] CREATE TS ERROR: " + exCreate.Message.ToString(), exCreate, "something went wrong");
				//sbReturnString.Append("[EXACTTARGET] CREATE TS ERROR: " + exCreate.Message).AppendLine();
				//lblMessage.Text += "<br/><br/>CREATE TS ERROR:<br/>" + exCreate.Message;
				throw;
			}
		}
Ejemplo n.º 8
0
        public void Trigger(ExactTargetTriggeredEmail exactTargetTriggeredEmail, RequestQueueing requestQueueing = RequestQueueing.No, Priority priority = Priority.Normal)
        {
            var clientId = _config.ClientId;
            var client   = SoapClientFactory.Manufacture(_config);

            var subscriber = new Subscriber
            {
                EmailAddress  = exactTargetTriggeredEmail.EmailAddress,
                SubscriberKey = exactTargetTriggeredEmail.SubscriberKey ?? exactTargetTriggeredEmail.EmailAddress,
                Attributes    =
                    exactTargetTriggeredEmail.ReplacementValues.Select(value => new Attribute
                {
                    Name  = value.Key,
                    Value = value.Value
                }).ToArray()
            };

            // Add sender information if specified. This will send the email with FromAddress in the sender field.
            // Official doco here under the section "Determining the From Information at Send Time":
            // https://help.exacttarget.com/en/technical_library/web_service_guide/triggered_email_scenario_guide_for_developers/#Determining_the_From_Information_at_Send_Time
            if (!string.IsNullOrEmpty(exactTargetTriggeredEmail.FromAddress) && !string.IsNullOrEmpty(exactTargetTriggeredEmail.FromName))
            {
                subscriber.Owner = new Owner()
                {
                    FromAddress = exactTargetTriggeredEmail.FromAddress,
                    FromName    = exactTargetTriggeredEmail.FromName
                };
            }

            var subscribers = new List <Subscriber> {
                subscriber
            };

            var tsd = new TriggeredSendDefinition
            {
                Client = clientId.HasValue ? new ClientID {
                    ID = clientId.Value, IDSpecified = true
                } : null,
                CustomerKey = exactTargetTriggeredEmail.ExternalKey
            };

            var ts = new TriggeredSend
            {
                Client = clientId.HasValue ? new ClientID {
                    ID = clientId.Value, IDSpecified = true
                } : null,
                TriggeredSendDefinition = tsd,
                Subscribers             = subscribers.ToArray()
            };

            var co = new CreateOptions
            {
                RequestType            = requestQueueing == RequestQueueing.No ? RequestType.Synchronous : RequestType.Asynchronous,
                RequestTypeSpecified   = true,
                QueuePriority          = priority == Priority.High ? ExactTargetApi.Priority.High : ExactTargetApi.Priority.Medium,
                QueuePrioritySpecified = true
            };

            string requestId, status;
            var    result = client.Create(
                co,
                new APIObject[] { ts },
                out requestId, out status);

            ExactTargetResultChecker.CheckResult(result.FirstOrDefault()); //we expect only one result because we've sent only one APIObject
        }