This script is titled ForwardMail.scpt and is located in “~/Library/Application Scripts/com.apple.mail” directory.
The desire is to run this Applescript in a Mail rule that acts on messages that arrive to my in box with certain criteria. I want to forward the selected emails, including any attachments, after adding YYYY-MM-DD SPACE to the begining of the incoming message subject.
My Mail rule is set as “If any of the following conditiond are met: Subject contains test, Perform the following actions: Run Applescript ForwardMail.”
using terms from application "Mail"
on perform mail action with messages tMsgs for rule tsRul --Is this necessary? I've tried both ways.
tell application "Mail"
repeat with aMsg in tMsgs
set fwdMsg to forward aMsg -- with opening window <--Is this necessary? I've tried both ways.
tell fwdMsg
activate
set sentDate to (short date string of (get date sent of aMsg))
set datedSubject to sentDate & space & subject of aMsg
set subject to datedSubject
make new to recipient with properties {address:"RecipiantAddress", visible:true}
-- send fwdMsg -- I want to review some test forwarding messages before I activate this command with "visible:true" above
end tell
end repeat
end tell
end perform mail action with messages
end using terms from
The problem is I am not seeing any forwarded message and it appears that Mail is not even running the script. When I send a test message nothing happens. I know the rule works because I can change the “Run Applescript” to “Delete” and the test message gets deleted. However, when I add some “say” or “display dialog” commands, nothing. How do I fix this?