Mail Rules, AppleScript not working after Upgrade to Mountain Lion

Alt Text

A while back we set up an Applescript to reply to incoming PayPal payment notification emails. This stopped working when we upgraded our Mac to Mountain Lion 10.8. Actually, the rule was working sporadically, but not every time (nice huh!). It appears the script didn’t like looking at the incoming messages, so we changed the message to look at ALL messages in the Inbox, and fire when appropriate.

Our rule first moves the incoming PayPal email notification to a “Sales” mailbox and flags the email so that we can identify new emails. Then it fires the applescript.

Here is what the code looks like now:

using terms from application "Mail"
    tell application "Mail"
        repeat with eachMessage in (every message of mailbox "Sales")
            set flagIndex to (flag index of eachMessage)
            if flagIndex is not -1 then
                set theContent to content of eachMessage
                    try
                        -- unflag the email so that it doesn't fire next time the script runs
                        set the flag index of eachMessage to -1
                        -- get the buyers email address from within the paypal notification email
                        set AppleScript's text item delimiters to {"(", ")"}
                        set contentParts to (every text item in theContent) as list
                        set AppleScript's text item delimiters to ""
                        set emailOnly to item 2 of contentParts
                        set recipientAddress to emailOnly
                        set theSubject to "Your subject here"
                        set theSendContent to "Your content here"
                        set theSender to "your email address here"
                        set theMessage to make new outgoing message with properties {subject:theSubject, content:theSendContent, sender:theSender, visible:true}
                        tell theMessage
                            make new to recipient with properties {address:recipientAddress}
                            send
                        end tell
                    end try
            end if
        end repeat
    end tell
end using terms from

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>