This is my first time making an Applescript. The script redirects mail based on several rules setup inside Apple Mail. My problem is that when the message is redirected to the new recipient, they receive it just fine but it has duplicated the Body of the email once for every Rule setup inside Apple mail. I cant figure out why it is doing that so I thought perhaps if I manually enter the Rules inside the Applescript and bypass using Apple Mail for the Rules, it would solved the problem. I cant figure out how to write the rules in Applescript. Here are my rules setup in Apple Mail:
If All of the following conditions are met:
Account - Dchiusa
From - Contains: livechatinc.com
Message Content - Contains: donald
Message Content - Contains: duration
Below is my Applescript. If someone could help with this, thank you very much. Ive been using Applescript for 2 days and trying to learn this.
If All of the following conditions are met:
Account - Dchiusa
From - Contains: livechatinc.com
Message Content - Contains: donald
Message Content - Contains: duration
Below is my Applescript. If someone could help with this, thank you very much. Ive been using Applescript for 2 days and trying to learn this.
Code:
using terms from application "Mail"
on perform mail action with messages theMessages
repeat with thisMessage in theMessages
tell application "Mail"
set theText to content of thisMessage
set newMessage to redirect thisMessage with opening window
tell newMessage
set subject of newMessage to "Live Chat Transcript@Live Chat"
make new to recipient at beginning of to recipients with properties {address:emailaddress}
end tell
set the sender of newMessage to emailaddress
send newMessage
end tell
end repeat
end perform mail action with messages
end using terms from