I need to create a script that is run when a certain Mail Rule is met. So far no problem.
The script should then copy the senders email address, the subject line and the message body.
Now the script should active FileMaker (running on the same machine), create a new record and basically paste the three fields into the appropriate fields in the Filemaker database.
That’s it.
Any hand-holding is greatly appreciated.
Gary
Model: G5
AppleScript: 1.1
Browser: Safari 412.2
Operating System: Mac OS X (10.4)
Try this one - save it as a script and set a rule in Mail that applies to every message and runs the script. Change the variable/database/field names to suit. It’s not a very good script but at least it’s easy to follow so you can change it.
tell application "Mail"
set the_selection to (get selection)
repeat with this_message in the_selection
tell this_message
set the_sender to get sender
set the_subject to get subject
set the_body to get content
tell application "FileMaker Pro"
activate
create new record at end of database "test.fp5"
set cell "The_sender" of last record of database "test.fp5" to the_sender
set cell "the_subject" of last record of database "test.fp5" to the_subject
set cell "the_body" of last record of database "test.fp5" to the_body
end tell
end tell
end repeat
end tell
We are almost there. Unfortunately the email does not get “selected” even when the mail rule is met. The script must first select the mail that met the criteria in order to pass on the data to FileMaker.
The “set the_selection to (get selection)” command does not work, since there is no selection in the first place.
Someone is bound to come up with something better (I use Entourage) but this works for me:
using terms from application "Mail"
on perform mail action with messages theseMails
repeat with thisMail in theseMails
tell thisMail
set the_sender to get sender
set the_subject to get subject
set the_body to get content
end tell
tell application "FileMaker Pro"
activate
create new record at end of database "test.fp5"
set cell "The_sender" of last record of database "test.fp5" to the_sender
set cell "the_subject" of last record of database "test.fp5" to the_subject
set cell "the_body" of last record of database "test.fp5" to the_body
end tell
set read status of thisMail to true
end repeat
end perform mail action with messages
end using terms from