Creating Hard Bounces for Sitecore Email Experience Manager in code

This week I’ve been working on integrating with a 3rd party API for when Sitecore Email Experience Manager receives a hard bounce from a contact’s email account.

Creating the processor for the <exm.recipientListManagement.add> pipeline is quite easy as per usual but mimicking a hard bounce isn’t as easy as I thought.

Over on Sitecore Slack, Pete Navarra had a good idea of sending an email to a hard bounced account like this stack overflow answer but that wasn’t an option for me as on my dev machine all the EXM emails are getting caught by my local Papercut SMTP server.

Luckily with a few messages to the rest of the team I’m working with, someone had already done this by building up a bounce message, encrypting the details and then passing it into a BouncedMessageHandler.

Here’s a snippet of code to do it:

IStringCipher stringCipher = 
  Factory.CreateObject("exmAuthenticatedCipher", true) as IStringCipher;

if (stringCipher != null)
{
    BouncedMessageHandler bouncedMessageHandler = 
      new BouncedMessageHandler(
    Factory.CreateObject("exm/bouncedMessagesTaskPool", true) 
       as ShortRunningTaskPool,
    Factory.CreateObject("exm/recipientListManagementTaskPool", true) 
       as ShortRunningTaskPool);

    Random random = new Random();
    string messageId = "5beff565-cccb-4a36-83ba-17f66872d770";
    string contactId = "0a53d8ce-77e1-4c30-a903-9f128535fa99";
    string emailAddress = "test@test.com";

    List<Bounce> bouncedMessages = new List<Bounce>
    {
        new Bounce
        {
            Id = random.Next().ToString(),
            BounceReason = "reason",
            BounceType = BounceStatus.HardBounce,
            CampaignId = "",
            ContactId = stringCipher.Encrypt(contactId),
            EmailAddress = emailAddress,
            MessageId = stringCipher.Encrypt(messageId)
        }
    };

    bouncedMessageHandler.HandleReportedMessages(bouncedMessages);
}

 

Creating Hard Bounces for Sitecore Email Experience Manager in code

Moving email campaigns between environments in Sitecore

I’ve been doing a lot of work with Email Experience Manager recently and when I’ve installed a package on the target environment containing the items for the campaign they don’t appear in the EXM interface even though they appear in the Sitecore tree.

One simple question over on the Sitecore Slack Channel and Steve McGill pointed me in the direction to get it fixed.

Once your items have been imported into your target environment you can go to the EXM admin page at {CMURL}/sitecore/admin/messagestatistics.aspx

exm-admin-page-sitecore

You then click on the Upgrade button it will find the newly imported emails and create a Sitecore SQL campaign record if it doesn’t exist already.

You will now see your imported campaigns in Email Experience Manager.

For automated messages that I am using, there also seems to be one final link between the Campaign Item and the Email Message Item that also needs to be connected in order for tracking to work. The one way to kick this in to gear is to open the message in EXM, click on the “Full email campaign” link, click on the “Delivery” tab and then click the “Deactivate” button and then once that completes, click on the “Activate Message” button and the link between the two items will be created.

 

Moving email campaigns between environments in Sitecore