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.
  • The output of the Web context, as an integral 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.
  • 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).

    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, you need to create a Control Script that specifies parts; see Parts: splitting and renaming email attachments.

    This topic explains how to attach files other than those generated by the Print or Web context.

    Attaching external files

    To attach files other than those generated by the Print or Web context to Email output:

    1. Add the files to the template (see Adding images) or put them in a folder that is available to the machine that outputs the emails.
    2. Create a script: on the Scripts pane at the bottom left, click New. A new script appears in the list. Double-click on it to open it. If you are not familiar with scripts, see Writing your own scripts for an explanation of how scripts work.
    3. Change the name of the script, so that it reflects what the script does.

    4. Choose the option Selector and in the Selector field, type head.
    5. Write a script that appends a <link> element to the results (the selector is head, so the results contain the <head> of the email). For example:
      results.append("<link rel='related' href='images/letter-CU00048376.pdf'>");
      • Make sure to set the rel attribute to related.
      • The href attribute determines where the file comes from.
        For resources inside the template, use 'images/file.extension' , or 'fonts/myfont.otf', etc.
        For external resources, you need the full path to the file, for example: 'file:///c:/resources/attachments/instructions.pdf'
        or, for a remote file:
        'http://localhost:8080/pod/v1/deliverynotes/{8FCEC8BC-72E8-486B-A206-516BF10E21F6}'.
        Of course, you can also use dynamic calls such as 'file:///c:/clientfiles/' + record.fields.client_id + '/invoices/' + record.fields.invoice_number + '.pdf'.
      • Add the title attribute to specify a custom attachment name. For example:
        results.append("<link rel='related' href='images/{8FCEC8BC-72E8-486B-A206-516BF10E21F6}.pdf' title='INV1375461.pdf'>");

    Examples

    The following script attaches a PDF file named letter-CU00048376.pdf to each generated email. The PDF file is located in the Images folder on the Resources panel.

    results.append("<link rel='related' href='images/letter-CU00048376.pdf'>");

    If that same file would be located on the C: drive, the script should refer to it as follows: href='file:///C:/letter-CU00048376.pdf'.

    The link doesn't have to be static; you could use data from the record set to build the link, for example:

    var customerID = record.fields.ID;
    results.append('<link rel="related" href="images/letter-' + customerID + '.pdf">');

    Renaming attachments

    External files that are sent as attachments can be renamed via the script that attaches them to the email, by putting their intended name in the title attribute. For example:
    results.append("<link rel='related' href='images/{8FCEC8BC-72E8-486B-A206-516BF10E21F6}.pdf' title='INV1375461.pdf'>");

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

     
    • Last Topic Update: 28, November, 2017 04:27 AM
    • Last Published: 23, May, 2019 01:55 PM