We're building an email template in Marketing Cloud Email Studio where we're passing the HTML content of the email dynamically as subscriber value.

The template looks simply like


Now, we're trying to add email attachments but trying to figure out best way to do this.

Adding an Ampscript block like below to the template works just fine:

var @fileName, @fileAlias
set @fileName = "http://www.africau.edu/images/default/sample.pdf"
set @fileAlias = "test.pdf"
AttachFile('HTTP', @fileName,@fileAlias)

But we're looking at bit more dynamic control over the attachments and having ability to pass them dynamically to marketing cloud.

We've tried adding the ampscript block to the html code we're sending (email_contents_html subscriber attribute), but that just results in script rendered inline in the content and not executed.

Is there any way to accomplish what we're trying to achieve here, i.e. being able to pass Ampscript block to be executed in the email as part of subscriber attributes or something else from outside the marketing cloud?

1 Answer 1


You need to wrap your content into TreatAsContent function call. Only this way, the ampscript held in the email_contents_html will be processed.


In your current code, it is simply treated as simple text, and displayed without being processed at all.

  • Thanks! That worked like a charm, exactly what we needed
    – Tom Dracz
    Commented Mar 16, 2021 at 12:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .