AttachFile()
Attaches a file to an outgoing email message. You can optionally configure this function to include a link to the file when the email is viewed as a web page.
Before you use this function, you must enable AMPscript email attachments. Contact your Salesforce account executive for more information about enabling this capability.
You can also contact your account executive to adjust the error threshold that causes the send job to stop prematurely. This feature helps prevent a single error from stopping the entire job.
The AttachFile()
function has eight parameters:
fileLocationType
(string): Required. The type of location to pull the file from. Accepted values:http
,ftp
,portfolio
,contentbuilder
.fileLocation
(string): Required. The location to pull the file from. This parameter can contain a maximum of 2088 characters. If you specifyhttp
for the first parameter, this parameter must contain a URL. If you specifyftp
for the first parameter, this parameter must contain the name of a file in the Import folder of your Enhanced FTP site. If you specifyportfolio
orcontentbuilder
for the first parameter, this parameter must contain the external key of the file to attach.attachmentFileName
(string): The name assigned to a file when it’s attached to an email message. If you don't specify a new name, the function uses the original file name. If you specifyhttp
for the first parameter and don't provide a value for this parameter, the function uses the Content-Disposition information from the HTTP header. If the server providing the file doesn’t provide Content-Disposition information, the function uses an auto-generated value.boolViewOnWeb
(boolean): Iftrue
, a link to the file is included when a recipient selects the "View as a Web Page" link in the email. Iffalse
, the link is omitted. You can only use this parameter if the value of the first parameter ishttp
.viewOnWebLocation
(string): The URL to use when including a link to the file in the "View as a Web Page" context. If the value ofboolViewOnWeb
is true, you must provide a value for this parameter. You can only use this parameter if the value of the first parameter ishttp
.viewOnWebFileName
(string): The file name to use when including a link to the file in the "View as a Web Page" context. You can only use this parameter if the value of the first parameter ishttp
.viewOnWebDuration
(number): The number of days the link appears in the "View as a Web Page" context. You can only use this parameter if the value of the first parameter ishttp
.boolContentDispositionAttachment
(boolean): Iftrue
, the function changes the value of thecontent-disposition
header for the attachment toattachment
. Iffalse
, the value of this header is set toinline
.
You can use the AttachFile()
function to attach the types of files listed in this table to your emails.
File Type | MIME Type |
---|---|
doc | application/msword |
application/pdf | |
rtf | application/rtf |
pkpass | application/vnd.apple.pkpass |
xls | application/vnd.ms-excel |
ppt | application/vnd.ms-powerpoint |
docm | application/vnd.ms-word.document.macroEnabled.12 |
pptx | application/vnd.openxmlformats-officedocument.presentationml.presentation |
xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
docx | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
rar | application/x-rar-compressed |
ics | application/ics |
xml | application/xml |
zip | application/x-zip-compressed |
zip | application/zip |
wav | audio/wav |
wav | audio/x-wav |
gif | image/gif |
jpeg | image/jpeg |
jpg | image/jpeg |
jpg | image/jpg |
png | image/png |
png | image/x-png |
tif | image/tiff |
tiff | image/tiff |
ics | text/calendar |
csv | text/csv |
htm | text/html |
html | text/html |
txt | text/plain |
rtf | text/rtf |
vcf | text/vcard |
vcf | text/x-vcard |
xml | text/xml |
mp4 | video/mp4 |
To use this function, specify the type of location where the file is stored, and the location or external key of the file. You can optionally specify additional parameters.
This function supports secure transmission over HTTPS. If the remote server doesn’t respond to the AttachFile()
call within 30 seconds, the send is rescheduled for 15 minutes later.
You can only attach files contained in the account used to send the email message. This function doesn’t support shared content from Content Builder or Portfolio.
This example attaches a PDF document from a website to your outgoing email. In this example, a link to the file doesn’t appear when the recipient clicks the "View as a Web Page" link in the email.
This example attaches a Word document from the Import folder of the Enhanced FTP site.
This example attaches a PDF file from a website and gives the file a new name. The specified name is shown to the recipient of the email.
This example attaches a PDF file from a website, gives it a new name, and sets the value of the boolViewOnWeb
parameter to true. When this parameter is true
, you must also specify the URL that you want to link to in the "View as a Web Page" context. The URL that you specify can be different from the URL of the file that is attached to the email. You must also specify the link text to include.
The final parameter indicates that the link only remains active in the "View as a Web Page" context for four days.
- Email Attachments in the Marketing Cloud Engagement Email Help documentation