Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nicholaspaul

macrumors newbie
Original poster
Aug 1, 2006
2
0
Calgary AB
Hi there
I'm trying to develop a script that will filter emails for me.
If I get an email with an attachment, I want the script to email my Blackberry with a notification message, stating that I got an email with an attachment. If there is no attachment, I want the email simply forward to my Blackberry.

I have the following script in a rule, but every time it runs I get ''Error 8: NSInternal message'.
Code:
using terms from application "Mail"
   on perform mail action with messages theMessages for rule theRule
       repeat with eachMessage in theMessages
           tell application "Mail"
               try
                   set thesubject to subject of eachMessage
                   set theSender to sender of eachMessage
                   set bytes to message size of eachMessage
                   set thebody to content of eachMessage
                   -- conditional loop
                   set myAttachments to every mail attachment of theMessages
                   if count (items of myAttachments) < 1 then
                       --do the forward of the email that has no attachments
                       set newMessage to make new outgoing message with properties {subject:thesubject & "From" & theSender, content:thebody, sender:"mailer@mydomain.com", visible:true}
                       tell newMessage
                           make new to recipient at end of to recipients with properties {name:"Filtering", address:"me@phoneco.blackberry.net"}
                           send
                       end tell

                   else -- send attachment notification
                       set newMessage to make new outgoing message with properties {subject:"New mail + attachment", content:"You've got a new message sent to Contact from " & theSender & ", Subject: " & thesubject & ". Size of message: " & bytes & " bytes. ", sender:"mailer@mydomain.com", visible:true}
                       tell newMessage
                           make new to recipient at end of to recipients with properties {name:"Filtering", address:"me@phoneco.blackberry.net"}
                           send

                       end tell
                   end if
               on error the error_message number the error_number
                   display dialog " Error: " & the error_number & ". " & the error_message buttons {"Cancel"} default button 1
               end try
           end tell
       end repeat
   end perform mail action with messages
end using terms from

Any and all insight gratefully appreciated!

~Nicholas
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.