Friday, November 15, 2024

Applescript folder action to email file

I think the error came from the variable you have set on line 1 of your script. Setting a variable like this is not necessary and can cause errors. Just remove this variable and change its name on line 9 (below l.7) to your email app1 in double quotes. Here is the whole script (see l.7 for corrections) :

on adding folder items to this_folder after receiving added_items
    repeat with added_item in added_items
        tell application "Finder"
            set file_extension to name extension of added_item
            if file_extension is "eml" then
                set file_path to quoted form of POSIX path of added_item
                tell application "Microsoft Outlook"
                    activate
                    set new_message to make new message with properties {visible:true}
                    set message_content to read file file_path as «class utf8»
                    tell new_message
                        set message_subject to subject of (first message of (import message from message_content))
                        set message_body to content of (first message of (import message from message_content))
                        set message_attachments to every mail attachment of (first message of (import message from message_content))
                        set subject to message_subject
                        set content to message_body
                        repeat with attachment_file in message_attachments
                            make new attachment with properties {file name:attachment_file}
                        end repeat
                    end tell
                end tell
            end if
        end tell
    end repeat
end adding folder items to

1 According to your script, I can see your email app is “Microsoft Outlook”, that’s what I have included in the script (l.7).

Related Articles

Latest Articles