---
schema_version: "1"
id: 884642b55398f1840661c46bd3532a2c0912bb7a92f76973dfb46efa2a0fcc9b
title: AttachFile()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/content/mc-ampscript-reference-content-attach-file.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-attach-file.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 20ad9647d725274d91cb862ac47d324b014dd2b4e5594a25b556763123e31b9b
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# 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.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>❌ No</td>
  </tr>
</table>

## Syntax

```
AttachFile(fileLocationType, fileLocation,
           attachmentFileName,
           boolViewOnWeb, viewOnWebLocation,
           viewOnWebFileName, viewOnWebDuration,
           boolContentDispositionAttachment)
```

The `AttachFile()` function has eight parameters:

- `fileLocationType` (string): Required. The type of location to pull the file from. Accepted values: `http`, `ftp`, `contentbuilder`.
- `fileLocation` (string): Required. The location to pull the file from. This parameter can contain a maximum of 2088 characters. If you specify `http` for the first parameter, this parameter must contain a URL. If you specify `ftp` for the first parameter, this parameter must contain the name of a file in the Import folder of your Enhanced FTP site. If you specify `contentbuilder` 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 specify `http` 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): If `true`, a link to the file is included when a recipient selects the "View as a Web Page" link in the email. If `false`, the link is omitted. You can only use this parameter if the value of the first parameter is `http`.
- `viewOnWebLocation` (string): The URL to use when including a link to the file in the "View as a Web Page" context. If the value of `boolViewOnWeb` is true, you must provide a value for this parameter. You can only use this parameter if the value of the first parameter is `http`.
- `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 is `http`.
- `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 is `http`.
- `boolContentDispositionAttachment` (boolean): If `true`, the function changes the value of the `content-disposition` header for the attachment to `attachment`. If `false`, the value of this header is set to `inline`.

## Supported File Types

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                                                        |
| pdf       | 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                                                                 |

## Usage

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.

### Basic Usage

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.

```
%%=AttachFile('HTTP','http://example.com/catalog.pdf')=%%
```

### Basic Usage with File Hosted on Enhanced FTP Site

This example attaches a Word document from the Import folder of the Enhanced FTP site.

```
%%=AttachFile('FTP','productCatalog.doc')=%%
```

### Renaming the File

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.

```
%%=AttachFile('HTTP','http://example.com/catalog.pdf','newFileName.pdf')=%%
```

### Specifying Link Text for the "View as a Web Page" Context

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.

```
%%=AttachFile('HTTP','http://example.com/catalog.pdf','newFileName.pdf',true,'http://example.com/catalog.pdf','Click here to download your catalog',4)=%%
```

## See Also

- [Email Attachments](https://help.salesforce.com/s/articleView?id=mktg.mc_es_email_attachments.htm) in the Marketing Cloud Engagement Email Help documentation
