private void SendEmailCampaign(string newItemId, Sitecore.XConnect.ContactIdentifier identifier, Guid emailCampaignId)
        {
            var secret    = Sitecore.Configuration.Settings.GetSetting("TokenSecretKey");
            var encrypted = Tokenizer.Tokenizer.Encrypt(newItemId, secret);
            var url       = LinkManager.GetItemUrl(Sitecore.Configuration.Factory.GetDatabase("master").GetItem(Sitecore.Context.Site.StartPath), new ItemUrlBuilderOptions {
                AlwaysIncludeServerUrl = true
            });

            var messageOpitons = new AutomatedMessage();

            //Required Parameters
            messageOpitons.MessageId         = Guid.Parse(Templates.EmailCampaignMessageId);
            messageOpitons.ContactIdentifier = identifier;

            //Custom Tokens - Optional
            var tokens = new Dictionary <string, object> {
                { "urlwithtoken", $"{url}?t={encrypted}" }
            };

            messageOpitons.CustomTokens = tokens;

            //Language - Optional
            messageOpitons.TargetLanguage = "en";

            //Send Message
            ClientApiService.SendAutomatedMessage(messageOpitons);
        }
示例#2
0
        protected virtual void SendMail(ContactIdentifier toContact, Dictionary <string, object> customTokens, Guid messageId)
        {
            var automatedMessage = new AutomatedMessage();

            automatedMessage.ContactIdentifier = toContact;
            automatedMessage.MessageId         = messageId;
            automatedMessage.CustomTokens      = customTokens;
            automatedMessage.TargetLanguage    = Sitecore.Context.Language.Name;
            clientApiService.SendAutomatedMessage(automatedMessage);
        }
示例#3
0
 private void SendAutomatedMessage(AutomatedMessage automatedMessage)
 {
     if (clientApiService != null)
     {
         clientApiService.SendAutomatedMessage(automatedMessage);
     }
     else
     {
         var automatedMessageBus = ServiceLocator.ServiceProvider.GetService <IMessageBus <AutomatedMessagesBus> >();
         automatedMessageBus.Send(automatedMessage);
     }
 }
示例#4
0
        /// <summary>
        /// Executes the action with the specified <paramref name="data" />.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="formSubmitContext">The form submit context.</param>
        /// <returns><c>true</c> if the action is executed correctly; otherwise <c>false</c></returns>
        protected override bool Execute(SendEmailData data, FormSubmitContext formSubmitContext)
        {
            Assert.ArgumentNotNull(data, nameof(data));
            Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));
            var firstNameField = GetFieldById(data.FirstNameFieldId, formSubmitContext.Fields);
            var lastNameField  = GetFieldById(data.LastNameFieldId, formSubmitContext.Fields);
            var emailField     = GetFieldById(data.EmailFieldId, formSubmitContext.Fields);

            if (firstNameField == null && lastNameField == null && emailField == null)
            {
                return(false);
            }
            using (var client = CreateClient())
            {
                try
                {
                    var source = "Subcribe.Form";
                    var id     = CurrentTracker.Contact.ContactId.ToString("N");
                    CurrentTracker.Session.IdentifyAs(source, id);
                    var trackerIdentifier = new IdentifiedContactReference(source, id);
                    var expandOptions     = new ContactExpandOptions(
                        CollectionModel.FacetKeys.PersonalInformation,
                        CollectionModel.FacetKeys.EmailAddressList);
                    Contact contact = client.Get(trackerIdentifier, expandOptions);
                    SetPersonalInformation(GetValue(firstNameField), GetValue(lastNameField), contact, client);
                    SetEmail(GetValue(emailField), contact, client);
                    client.Submit();
                    if (data.MessageId == Guid.Empty)
                    {
                        Logger.LogError("Empty message id");
                        return(false);
                    }
                    ContactIdentifier contactIdentifier = null;
                    if (contact != null)
                    {
                        contactIdentifier = contact.Identifiers.FirstOrDefault <ContactIdentifier>((ContactIdentifier c) => c.IdentifierType == ContactIdentifierType.Known);
                    }
                    if (contactIdentifier == null)
                    {
                        Logger.LogError("Contact id is null.");
                        return(false);
                    }
                    try
                    {
                        _clientApiService.SendAutomatedMessage(new AutomatedMessage()
                        {
                            ContactIdentifier = contactIdentifier,
                            MessageId         = data.MessageId
                        });
                    }
                    catch (Exception exception1)
                    {
                        Logger.LogError(exception1.Message, exception1);
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex.Message, ex);
                    return(false);
                }
            }
        }