AttachFile

Overview

Attaches a file to an outgoing email message and can include a link to the file when you view the email as a web page. Contact your Marketing Cloud account representative to enable AMPscript email attachments for your account before using this function. You can also contact your account representative 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.

Syntax

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

Function Properties

OrdinalTypeDescription
1stringRequiredLocation from which to pull files. Valid values include HTTP, FTP, Portfolio (for Classic Portfolio), or ContentBuilder (for Content Builder).
2stringRequiredLocation from which to pull attachments. 2088 characters maximum. Specify a URL if you select HTTP. Specify the name of the file in the Import folder of your Enhanced FTP site if you select FTP. Specify the external key if you select Portfolio or ContentBuilder.
3stringName assigned to file when system attaches it to an email message. The function uses the original file name if you don't specify a new name. If you don't specify a value for the HTTP option, the function uses the Content-Disposition information from the HTTP header. If the server providing the file does not provide Content-Disposition information, the function uses an auto-generated value. For Content Builder, the file extension is dropped if you don't include the name and file extension.
4booleanIndicates whether a link to the attached file appears in View As A Web Page. Use only if string is HTTP.
5stringURL of the attachment link to use for View As A Web Page. Use only if string is HTTP.
6stringText for attachment link used in View As A Web Page. Use only if string is HTTP.
7intNumber of days the link appears in View As A Web Page. Use only if string is HTTP.
8booleanWhen true, changes the content-disposition from inline to attachment, when the default is inline.

Usage

This example attaches a PDF document from a website to your outgoing email. The email also includes a link to the file in View As A Web Page with the text 'Click here to download your catalog.' That link expires from View As A Web Page after four days.

If you want to rename the attachment, enter the optional filename argument as shown below:

The next example attaches a Word document from the import folder of the Enhanced FTP site. It also concatenates a new filename from the recipient's full name and the string 'NewCatalog.doc' at the time of attachment.

The following file types can be attached to emails sent through Marketing Cloud:

File TypeMIME Type
docapplication/msword
pdfapplication/pdf
rtfapplication/rtf
pkpassapplication/vnd.apple.pkpass
xlsapplication/vnd.ms-excel
pptapplication/vnd.ms-powerpoint
docmapplication/vnd.ms-word.document.macroEnabled.12
pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation
xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
rarapplication/x-rar-compressed
icsapplication/ics
xmlapplication/xml
zipapplication/x-zip-compressed
zipapplication/zip
wavaudio/wav
wavaudio/x-wav
gifimage/gif
jpegimage/jpeg
jpgimage/jpeg
jpgimage/jpg
pngimage/png
pngimage/x-png
tifimage/tiff
tiffimage/tiff
icstext/calendar
csvtext/csv
htmtext/html
htmltext/html
txttext/plain
rtftext/rtf
vcftext/vcard
vcftext/x-vcard
xmltext/xml
mp4video/mp4

This function supports secure transmission over HTTPS. If the remote server does not respond to the AttachFile() call within 30 seconds, the send reschedules for 15 minutes later and tries again.

You can only attach files contained in the account used to send the email message. This function does not support shared content from Content Builder or Portfolio.

Review additional information about email attachments.