Email attachments

Output, generated from an Email template, can have the following attachments:

  • The contents of the Print context, in the form of a single PDF attachment. (Compression options for PDF attachments can be specified in the Email context's properties; see Compressing PDF attachments.)
  • The output of the Web context, as a self-contained HTML file.
  • Other files, an image or a PDF leaflet for example.

Attaching the Print context and/or the Web context is one of the options in the Send (Test) Email dialog.

These options are also available in the Create Email Content task in Workflow.

Attaching a Context

By default, when adding the Print context to an email, all Print sections are output to a single PDF file, named after the email subject, which is then attached to the email.
The PDF can be protected with a password (see Email PDF password).
Compression options for PDF attachments can be specified in the Email Context Properties dialog; see Compressing PDF attachments.

When adding the Web context to an email, only the default Web section is generated and added to the email as an HTML file that is named after the email subject.

To split the Print context into multiple attachments, or to attach multiple Web sections as separate attachments, and to rename this type of attachment, you need to create a Control Script that specifies parts; see Parts: splitting and renaming email attachments.

A plain-text version of the HTML is added to each email if the option is checked in the Email section's properties (see Properties tab). With new templates this is always the case.

Attaching files

Selecting and adding files as attachments

If you want all recipients to get the same attachments with their email, you can add the attachments to the Email section(s).

The easiest way is to drag and drop the desired file on the Email section.
If the file is an image, you will be presented with the option to import it into the template's Resources folder. Any other file will be added to the list of attachments directly.

The Attachments dialog also lets you select files and delete attachments.
To open the Attachments dialog, right-click the Email section in the Resources pane and select Attachments.
Alternatively, select Section > Attachments from the menu. This menu item is only available when an Email section is opened in the workspace.

For further information about this dialog, see: Attachments dialog.

Dynamic attachments: creating file names based on data fields

The Dynamic Attachment Script Wizard lets you add a different attachment for each email recipient. It composes one file name (including the path) based on the value of one or more data fields.

The Dynamic Attachment wizard lets you concatenate this value with the base location and/or file extension to construct the path. Dynamic Attachment scripts are created via the New option on the toolbar of the Scripts panel.

  1. On the Scripts pane at the bottom left, click the downward pointing arrow next to the New button; then select Email Scripts > Dynamic Attachment.
    Note that an Attachments script creates one single attachment. To add more attachments, you could either add Attachments scripts, or click the Expand button and edit the script.
  2. A new script called Attachments has appeared in the list. Double-click to open it.
  3. Choose an Email section from the Section drop-down list.
  4. Fill in the different parts of which the file name is composed:
    • Prefix. The first prefix contains the base path (or at least the first, static part of the path). For example:C:\Attachments\, C:/Attachments/, or file:///C:/Attachments/.
    • Data field/s. The selected data field/s will be evaluated. If a data field is empty, the entire row is skipped. Otherwise the prefix, data field value and suffix are added to the path/file name.
    • Suffix. The suffix on the last used row should contain the file extension, including the dot (for example.pdf).

    For resources inside the template, refer to the folder in the Resources, e.g. 'images/file.extension' , or 'fonts/myfont.otf', etc.
    For any other file, give a valid URL.

    • Use the file protocol for a file on disk, for example: file:///c:/somefolder/attachments/INV2018.246.pdf (which equals file://localhost/c:/somefolder/attachments/INV2018.246.pdf; if the host is "localhost", it can be omitted).
    • For a remote file, you can use the http protocol e.g. http://www.mysite.com/somefolder/attachments/INV2019-246.pdf or
      http://localhost:8080/pod/v1/deliverynotes/{8FCEC8BC-72E8-486B-A206-516BF10E21F6}.

    For attachment names, it is recommended to use only US-ASCII characters. Other characters may not be supported by all email servers and clients.

    Certain characters are invalid in a URL (for example, '$', '%', and '&') and must be percent-encoded. The same applies to a file path, since that actually is a URL that starts with the file protocol.

    Note that even a space character is invalid in a URL. Spaces in a URL are supported for backward compatibility, but it is recommended to percent-encode a space character as %20.

  5. The attachment's name in the email will be the part of the path that comes after the last '/'. When there are no forward slashes in the path, the full path is used.
    You may want to use a custom attachment name. To learn how to do that, see Renaming attachments.
  6. Click OK or Apply to save your changes.

Note that an Attachments script creates one single attachment. To add more attachments, you could either add Attachments scripts, or click the Expand button and edit the script.

If you want to write your own email attachment scripts, there is a how-to that you may find helpful: How to add custom email attachments.

Renaming attachments

Sections that are attached to an email can only be renamed via a Control Script; see Parts: splitting and renaming email attachments.

Renaming dynamic attachments

Dynamic attachments can be renamed via the script that attaches them to the email. Double-click the script to open it and click the Expand button.

Dynamic attachment scripts add a <link> element to the <head> of an Email section. The title attribute of that element specifies the attachment name that will show up in the email.
Take a look at the last line of the script:
results.append(query("<link rel=related>").attr("title", result.split('/').pop()).attr("href", result));
To give the attachment another name, you have to replace the bold part of the code by that new name. For example:
results.append(query("<link rel=related>").attr("title", "Invoice.pdf").attr("href", result));
Of course, you can also use data field values here, for example: results.append(query("<link rel=related>").attr("title", record.fields.invoice_number + ".pdf").attr("href", result));

Note that the Wizard can no longer be used once you have edited and saved the script.

For attachment names, it is recommended to use only US-ASCII characters. Other characters may not be supported by all email servers and clients.