Skip to content

🔥 Join 600+ readers. Get our newsletter for code and tips.

Issue with  AMPscript domain() function in SMFC
> 999 views

Issue with AMPscript domain() function in SMFC

View favourites

Sometimes the unexpected currents of salesforce marketing cloud will take you to the issues you never experienced before. Recently we discovered that the function domain is not working within condition used in the email studio.

Wanted to add a restriction on our transactional email service to send emails only when the domain is whitelisted. Simple, right? We thought so too.

I knew there was a function in AMPScript that directly extracts the email domain from a given string.

Domain() function problem when sending email from salesforce marketing cloud

We used domain() function that does what it says. Extracts domain from any valid email string.

%%[ IF NOT EMPTY(Lookup("domain_whitelist","domain","domain", Domain(AttributeValue("EmailAddress")))) THEN]%%
  //send email
%%[ELSE]%%

Everything worked in the preview of the email in the content builder (email studio) — no questions asked. “QA” passed with five stars, all good to go. Ready for testing by the other team that like to send API calls.

Now a bit later we’re hearing back from the team that the template stopped working.
We assumed the issue was caused by the newly added AMPScript section and our domain feature.

So, we rebuilt the domain extraction logic using basic AMPScript functions. After clearing the cache, emails started flowing in again.

%%[
SET @email = LowerCase(Trim(AttributeValue("EmailAddress")))
SET @atIndex = IndexOf(@email, "@")
SET @domain = Substring(@email, Add(@atIndex, 1), Length(@email))
  
IF NOT EMPTY(Lookup("domain_whitelist","domain","domain", @domain)) THEN]%%
  //send email
%%[ELSE]%%

⛔ Do not use Domain() nested within another function!

I was not able to sleep and tried the domain() function work and found out that it has issues only when used inline. When you save results of the function to new variable and use the variable in the condition all works as expected

%%[ 
  SET @email = LowerCase(Trim(AttributeValue("EmailAddress")))
  SET @domain = Domain(@email)
  IF NOT EMPTY(Lookup("domain_whitelist", "domain", "domain", @domain)) THEN 
]%%
// send email
%%[ ELSE ]%%

💡 Possible explanation for why Domain() fails when nested within another function

We encounter similar issue with nested indexOf function within one line AMPScript code call. It seems like AMPScript sometimes fails to evaluate nested function calls reliably when used inline inside another function like Lookup(). Especially when functions like Domain() depend on dynamic content (AttributeValue()), the engine might not process them in the expected order — resulting in empty or null values.

By assigning Domain(@email) to @domain, we’re forcing the evaluation before the Lookup() is run — which stabilizes the logic.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida dignissim volutpat. Vestibulum ante ipsum primis in faucibus orci luctus et…

🔒 Premium Subscriber Content

Already a Premium subscriber? Log in to continue reading, or register to create your account.

You must log in and have a Premium Subscriber account to read the full article.

When upgrading, please use the same email address as your WordPress account so we can correctly link your Premium membership.

Please allow us a little time to process and upgrade your account after the purchase. If you need faster access or encounter any issues, feel free to contact us at info@martechnotes.com or through any other available channel.

To join the Discord community, please also provide your Discord username after subscribing, or reach out to us directly for access.

You can subscribe even before creating a WordPress account — your subscription will be linked to the email address used during checkout.

Premium Subscriber

29,99 € / Year

  • Free e-book with all revisions - 101 Adobe Campaign Classic (SFMC 101 in progress)
  • All Premium Subscriber Benefits - Exclusive blog content, weekly insights, and Discord community access
  • Lock in Your Price for a Full Year - Avoid future price increases
  • Limited Seats at This Price - Lock in early before it goes up
  • Monthly 15-Minute Call - Discuss any topic directly

Oh hi there 👋
I have a SSJS skill for you.

Sign up now to get an SSJS skill that can be used with your AI companion

We don’t spam! Read our privacy policy for more info.

Share With Others

The author
Marcel Szimonisz Platinum

Marcel Szimonisz

Marketing Automation Consultant

I specialize in solving marketing technology challenges, automating processes, and turning ideas into practical solutions with Salesforce Marketing Cloud and Adobe Campaign. Through MarTechNotes, I share technical guides and insights that make complex topics easier to understand

Latest badges
Weekend Regular Weekend Regular Profile Complete Profile Complete Simple Start Simple Start 5 Day Streak 5 Day Streak First Comment First Comment

Your email address will not be published. Required fields are marked *

Get exclusive tips, scripts and news

Choose your topics

We don’t spam! Read our privacy policy for more info.

Similar posts

Add to this article

Share your experience

Your contribution

Article history

What changed