Exclude an email domain from a send

Sending tons of emails to certain email domains can be tricky, even if your sending IP address reputation is good. ┬áIn Salesforce Marketing Cloud, you can utilize an Audience Exclusion Script to isolate domains for special sending treatment — like throttling or sending at a certain time of day.

Here’s an example that utilizes the AMPScript domain() function and the emailaddr personalization string that’s present in every send context.

Email #1 – Exclude emails to comcast.net domains with an exclusion script:

domain(emailaddr) == "comcast.net"

Email #2 – Exclude emails except comcast.net domains with an exclusion script:

domain(emailaddr) != "comcast.net"

Email #2 would be configured with some throttling or be deployed only at a certain time of day.

Code goes here:

This solution will work for sends to Lists, Groups or Data Extensions.

If Exclusion Scripts are not enabled for your User-Initiated or Triggered Send Definitions, SFMC support can enable them for you.

Number Suffixes in AMPScript

Suppose you want to output a day of the month with a proper suffix (e.g. 1st, 13th). There aren’t any formatting functions in AMPScript to do it, but you can do it with a set of if-statements:

Output

1st
2nd
3rd
4th
5th
6th
7th
8th
9th
10th
11th
12th
13th
14th
15th
16th
17th
18th
19th
20th
21st
22nd
23rd
24th
25th
26th
27th
28th
29th
30th
31st

Once you’re satisfied that it works, you can simply remove the for-loop and un-comment the set @day = Format(Now(),"dd")) line

Reference

Prune rows in a Data Extension with SSJS

Say you want to delete a million rows from a Data Extension in Salesforce Marketing Cloud (SFMC). Doing that with the SFMC Web Services can be a pain. One alternative is to utilize Server-Side JavaScript (SSJS) and a Landing Page.

I built a landing page that posts to itself and runs this pruneRows() function. I configured a Data Extension that contains the keys to delete. The script retrieves all of the rows with that key, deletes them and updates the DE of keys with the results.

You may have to experiment with the number of Row Keys to retrieve at a time. If the number is too high, the landing page will time-out. In my scenario, I found that processing 50 at a time worked well (line #8).

For further reading:

Retrieving and Starting an Automation with SSJS

Server-side Script (SSJS) Activities are a hidden gem of the Salesforce Marketing Cloud. They’re useful for a wide range of applications. I ran into a scenario where I wanted to run an Automation programmatically — if it’s not already running.

It was way harder than it needed to be. Hope this saves you some frustration:

The retrieve is for getting the ObjectID and Status of the Automation, which you then use to check to see if it’s running and then invoke a Perform if it isn’t.

The frustrating part of this was that the ObjectID is not a retrieveable property of the Automation Object (unlike Status). It’s only returned in the result-set of a successful Retrieve.

I’d suggest testing this script in a Landing Page until you get it working and then move it to the Script Activity.

SFMC Support can enable Script Activities if there’s not a Script entry in the Interactions drop-down menu.

For further reading: