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
        }
Пример #2
0
		private TriggeredSend CreateTriggeredSendDefinitions(Subscriber subscriber, string triggeredSendDefinition)
		{
			TriggeredSend ts = new TriggeredSend();
			ts.Subscribers = new[] { subscriber };

			ts.TriggeredSendDefinition = new TriggeredSendDefinition();
			ts.TriggeredSendDefinition.CustomerKey = triggeredSendDefinition;

			return ts;
		}
        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);
                    }
                }
            }
        }
Пример #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
        }
Пример #6
0
        /// <summary>
        /// Trigger an email send to the specified subscriber using the 'Trigger Send Definition' key,
        /// <paramref name="triggerSendDefKey"/>.
        /// </summary>
        /// <remarks>Note that this function additionally creates a triggered send data extension and will create
        /// a duplicate even if the subscriber details are identical. It might be a good idea to fix this some
        /// day.</remarks>
        public ValResultData<int> SendEmailNow(string subscriberKey, string triggerSendDefKey, int listId,
                                               SubscriberBO subscriberBO)
        {
            if (_soapClientFactory == null)
                return ValResultDataFactory.NewFailure<int>("No SoapClientFactory provided to EmailSender");

            if (string.IsNullOrEmpty(subscriberKey))
                return ValResultDataFactory.NewFailure<int>("No subscriber key provided to EmailSender");

            if (string.IsNullOrEmpty(triggerSendDefKey))
                return ValResultDataFactory.NewFailure<int>("No trigger send definition key provided to EmailSender");

            Subscriber subscriber;
            if (subscriberBO != null)
            {
                subscriber = SubscriberFactory.New(subscriberBO, listId, _soapClientFactory);
            }
            else
            {
                subscriber = new Subscriber
                {
                    EmailAddress  = subscriberKey,
                    SubscriberKey = subscriberKey,
                };
            }

            var clientId = new ClientID
            {
                ID          = _soapClientFactory.SubAccountId,
                IDSpecified = true,
            };

            var send = new TriggeredSend
            {
                Client                  = clientId,
                Subscribers             = new[] { subscriber },
                TriggeredSendDefinition = new TriggeredSendDefinition
                {
                    CustomerKey = triggerSendDefKey,
                    Client      = clientId,
                },
            };

            APIObject[]    sends = {send};
            string         status;
            CreateResult[] results;

            try
            {
                string requestId;
                results = _soapClientFactory.Client.Create(new CreateOptions(), sends, out requestId, out status);
            }
            catch (Exception ex)
            {
                return ValResultDataFactory.NewFailure<int>("Failed to trigger email send. Exception details: {0}",
                                                            ex.Message);
            }

            if (!"OK".Equals(status, StringComparison.InvariantCultureIgnoreCase))
            {
                string errors = ETErrorResultExtractor.Extract(results);
                if (!string.IsNullOrEmpty(errors))
                    return ValResultDataFactory.NewFailure<int>("Failed to trigger email send. " +
                                                                "Exact Target errors are: {0}", errors);
            }

            if (results.Length == 0)
                return ValResultDataFactory.NewSuccess(0, "Failed to trigger email send. " +
                                                       "Unable to acquire error details.");

            return ValResultDataFactory.NewSuccess(0, "Successfully triggered email send");
        }
		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;
			}
		}
Пример #8
0
		private string ProcessTriggeredSend(TriggeredSend ts, CreateOptions createOptions)
		{
			string status;
			string sendResult;

			CreateResult[] results = _service.Client.Create(createOptions, new APIObject[] { ts }, out _requestID, out status);

			TriggeredSendCreateResult createResults = results[0] as TriggeredSendCreateResult;

			if (createResults != null)
			{
				if (status != "OK")
				{
					UnityResolver.UnityContainer.Resolve<ILogger>().LogEvent(() =>
						Config.AppEvents.GainWinServicesExactTarget.ExactTargetWarning,
						string.Format("Error during sending data to ExactTarget. ExactTarget.API.ProcessTriggeredSend. Error {0}",
						createResults.ErrorCode));

					sendResult = createResults.ErrorCode.ToString();
				}
				else
				{
					UnityResolver.UnityContainer.Resolve<ILogger>().LogEvent(() =>
						Config.AppEvents.GainWinServicesExactTarget.ExactTargetWarning,
						"Successful sending. ExactTarget.API.ProcessTriggeredSend");

					sendResult = string.Empty;
				}
			}
			else
			{
				sendResult = "Unexpected error";
			}

			return sendResult;
		}
Пример #9
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
        }