Search code examples
sitecoresitecore6sitecore-ecm

Sitecore ECM - Do not send to duplicate email addresses


Does anyone know if there is a setting in Sitecore ECM which will disable sending to duplicate email addresses (Sitecore 6.5 rev 706 ECM 1.3.2 rev 120424). I haven't found any mention in the dev docs - but it seems like it is a common requirement. Or am I going to need to override the send pipeline and implement this as custom functionality?

Cheers


Solution

  • Instead of override the send pipeline, you could add your own step to the DispatchNewsletter pipeline.

    In that pipeline you have access to all recipients, and can filter them.

    Here is some code that should work, but i haven't tested it

    public void Process(DispatchNewsletterArgs args)
    {
        // Lets not filter emails from engagement automation
        TargetAudienceBase targetAudience = args.Message.TargetAudience;
    
        if (targetAudience.Name != "Engagement Automation")
        {
            // Cleas who gets the email
            args.Message.SubscribersNames.Clear();
    
    
            // holds list of email address, and contancts.
            var emailSendingTo = new Dictionary<string, Contact>();
    
    
            // Filter all recipients from the targetAudience
            foreach (Contact contact in targetAudience.OptInList.Contacts.Except(targetAudience.OptOutList.Contacts))
            {
                if (!emailSendingTo.ContainsKey(contact.InnerUser.Profile.Email))
                {
                    emailSendingTo.Add(contact.InnerUser.Profile.Email, contact);
                }
            }
    
            // Add all the names to the subscriber list (domain/username)
            foreach (KeyValuePair<string, Contact> keyValuePair in emailSendingTo)
            {
                args.Message.SubscribersNames.Add(keyValuePair.Value.Name);
            }
    
        }
    }
    

    Inserting that step befor DeployAnalytics, makes analytics work as it should