Send email with attachment : how to attach multiple files


I am creating email templates using the action below, and some of those templates require me to attach multiple files.
According to KM Wiki below, there should be a way to attach multiple files. I could not find the solution in the forum.
thanks in advance for your time and help

Attaching Files

To attach a file click the File Chooser button to the right of the action to select an existing file on disk. Option-click on the File Chooser button to show the currently selected file in the Finder (assuming it exists already). You can only attach a single file (if you need more than one file, it can be done with AppleScript).

I don't know the first thing about AppleScript and Mail, so I thought I'd ask ChatGPT for its solution; here's what it offered up as a starting point:

-- Specify the email addresses, subject, and body of the email
set recipientAddress to ""
set subjectText to "Your Subject Here"
set bodyText to "Your Body Text Here"

-- Specify the file paths of the items you want to attach
set attachmentPaths to {"/path/to/file1.txt", "/path/to/file2.pdf", "/path/to/file3.jpg"}

-- Create a new outgoing message
tell application "Mail"
    set newMessage to make new outgoing message with properties {subject:subjectText, content:bodyText & return & return}
    -- Add recipient to the new message
    tell newMessage
        make new to recipient at end of to recipients with properties {address:recipientAddress}
        -- Attach files to the new message
        repeat with attachmentPath in attachmentPaths
            make new attachment with properties {file name:attachmentPath} at after the last paragraph
        end repeat
    end tell
    -- Activate Mail and display the new message
    set visible of newMessage to true
end tell

Hope that's enough to at least get you started!


1 Like

thank you very much Rob !