With the release of FileMaker Pro 17, a long-time feature request has been delivered – the ability to attach multiple files to an email.
The Send Mail script step is used to compose and send an email from a FileMaker solution.
The change in FileMaker 17 is the Attach Files button in the lower left. Clicking this button allows multiple file paths to be set:
Developers will usually specify a variable to define the file path. In past versions, this would have been a single path ending in a file name. In FileMaker 17, the variable can be a list of file paths, one for each attachment.
Attaching Multiple files to Email
So a script to send invoices for a current customer record looks like:
Go to Related Record [“Invoices”; only related] If [ Get ( LastError ) = 0 ] Go to Record/Request/Page[First] Loop Go to Related Record [ “Invoice Data”; only related; new window] Set Variable [$FILE; Value: calc below] Save Records as PDF [ File Name: “$FILE”] Set Variable [$LIST; Value:List($LIST; $FILE)] Close Window [Current Window] Go to Record/Request/Page[Next;Exit after last] End Loop Send Mail [ E-mail Client; Attachments: “$LIST”] End If
The $FILE variable is set with a calculation like:
Let ([ path = Get ( TemporaryPath ) ; file = "Inv_" & Invoices::Invoice ID & ".pdf" ]; path & file )
This value is used as the file name for Save Records as PDF. Each PDF will have a unique name and will be saved in the temporary path.
The $LIST variable is used to assemble all the file paths for the attachments. It is ultimately used in the Send Mail step. It appends each new file to a list for each loop using:
List ( $LIST; $FILE )
As with all new features, it is important to account for users who may not be running version 17 clients. Either the file needs to lock those users out, or the script needs to detect the client version and have modified action.