AttachFile

This function attaches the specified file to the outbound message or displays a link to the file when included in a landing page. This function returns no output.

The following file types can be attached to email messages in Marketing Cloud:

Extension Description
.doc Microsoft Word document
.docx Microsoft Word document
.gif GIF image
.ics ICS file
.jpeg JPEG image
.jpg JPEG image
.mp4 MPEG-4 video file
.pdf PDF document
.png PNG image
.ppt Microsoft PowerPoint document
.pptx Microsoft PowerPoint document
.rar WinRAR Compressed Archive
.tif TIFF image
.tiff TIFF image
.xls Microsoft Excel document
.xlsx Microsoft Excel document
.zip ZIP archive

NOTE: Marketing Cloud Support must provision this function for use in your account. There is typically an additional charge per attachment sent. Contact your Salesforce Account Executive to complete the process.

NOTE: If the specified file cannot be found at send time, the send will throw a runtime error and abort.

NOTE: The AttachFile function does support files referenced using the HTTPS protocol.

NOTE: If you are attaching an external file and the remote server does not respond within 30 seconds, the send will be scheduled to retry 15 minutes later.

NOTE: Local assets in shared Content Builder or Portfolio locations are not supported.

Arguments

AttachFile(1,2,3,4,5,6,7)

Ordinal Type Required Description
1 String True

Type of location containing the file to attach. Valid values include:

  • ContentBuilder
  • FTP
  • HTTP
  • Portfolio (Classic Content)
2 String True

Path or key of the asset to attach. Specify the following for the preceding location:

  • ContentBuilder – Customer/External Key of asset
  • FTP – Name of file in the Enhanced SFTP Import Folder
  • HTTP – HTTP/HTTPS URL of the asset
  • Portfolio – Customer/External Key of asset in Classic Content
3 String False

Alias assigned to file when attached. If no value is specified, the name of the file is used.

If you do not specify an alias for HTTP type asset, the Content-Disposition from the HTTP header will be used. If no Content-Disposition is provided, a system-generated value will be returned.

4 Boolean False

Show link to file in the View as a Web Page context. Default value is false.

This argument can only be used with the HTTP location type.

5 String False

URL of the attachment to use in the View as a Web Page context. Default value is false.

This argument can only be used with the HTTP location type.

6 String False

Link name for file in the View as a Web Page context.

This argument can only be used with the HTTP location type.

7 Number False

Number of days the link to download the file appears in the View as a Web Page context.

This argument can only be used with the HTTP location type.

NOTE: Arguments 4 – 7 are unavailable in the current release of Marketing Cloud. This should be resolved in a future release.

Example 1

This example attaches a Content Builder asset by Customer/External Key:

%%[

var @customerKey, @fileAlias
set @customerKey = "LoyaltyMembersCB"
set @fileAlias = "LoyaltyMembers_ContentBuilder.zip"

AttachFile("ContentBuilder", @customerKey, @fileAlias)

]%%

Example 2

This example attaches a file from the Marketing Cloud Import folder:

%%[

var @fileName, @fileAlias
set @fileName = "LoyaltyMembers.zip"
set @fileAlias = "LoyaltyMembers_FTP.zip"

AttachFile("FTP", @fileName, @fileAlias)

]%%

Example 3

This example attaches a file from an external website via HTTP/HTTPS:

%%[

var @fileName, @fileAlias
set @fileName = "https://limedash.com/drop/LoyaltyMembers.zip"
set @fileAlias = "LoyaltyMembers.zip"

AttachFile("HTTP", @fileName, @fileAlias)

]%%

Example 4

This example attaches a file from the Portfolio asset by Customer/External Key:

%%[

var @externalKey, @fileAlias
set @externalKey = "LoyaltyMembers"
set @fileAlias = "LoyaltyMembers_Portfolio.zip"

AttachFile("Portfolio", @externalKey, @fileAlias)

]%%