Script to send mail based on rule

Does anyone have an applescript to to send a message to anoher person’s mailbox based up meeting a condition of a mail rule? Thanks Ben

Hi Ben,

I’m answering here so we can stay on topic (I saw your plea for help with this in another thread). Which version of OS X/Mail are you running? I’ve heard that some parts of Mail’s scripting dictionary has changed in Panther.

– Rob (who’s not a Mail user)

Rob
10.3.2.
Thanks Ben

Unfortunately I’m still running Jaguar so I won’t be able to offer much help. Sorry. :confused:

Edit:

I did some checking around and there are indications that some of the old code still works in Panther. Here’s a script that might work, and it might be close to what you need. Make sure you modify the first four lines to suit your situation.

set recip_name to "Joe Blow"
set recip_address to "voo@doo.comm"
set subject_ to "Urgent"
set body_ to "Hey Joe! You need to shut down the nuclear plant ASAP."

on perform_mail_action(info)
	tell application "Mail"
		set nm to make new outgoing message with properties {content:body_, subject:subject_}
		tell nm
			make new to recipient at end of to recipients with properties {name:recip_name, address:recip_address}
		end tell
		set visible of nm to true
		send nm
	end tell
end perform_mail_action

– Rob

Rob
You are amazing.
I can’t thank you enough.
How can I ever pay you back?
Thanks Ben

Glad it worked.

Help someone who needs help. :wink:

– Rob

Hi Rob,

I just set an automatic reply to incoming mail to Mail with data from Filemaker.

I define the inquiry with the subject of the e-mail, and the data to search with the contains of the message.

For e-mails coming from Mail (mac) the set up works great, but if the incoming message as been issue with outlook I’m stuff on the line:

set jbNum to contents of Msg (jbNum my variable and Msg the handle to the message)

Looks like the incoming text format is not supported. I try to read as a string number… doesn’t work! But if I do View/message/Plain text alternative he works. Of course the command is not on the dictionary…

The event log show an "? instead the “4235” contain by the mail, and filemaker can not search the data.

Any idea how to read properly the contents of any e-mail

Thanks

First let me state that I’m not a Mail user and the only time that I fool with it is when attempting to help someone with a script. :wink:

You might try working with ‘source’ of the message instead of ‘content’. If the message contains HTML, or something other than plain text, this might require that you parse the text to find what you are looking for. I really don’t have much experience with this so I can’t be sure.

Good luck!

– Rob

Thanks Rob. :smiley:

I get the source… another mater is to get the content out of the source: I found hard to work thought strings on Applescript… as they say is nothing impossible with applescript: is just a mater of ow many h you can spend on it! :shock:

using terms from application "Mail" 
    on perform mail action with messages theMessages for rule theRule 
        tell application "Mail" 
            repeat with eachMessage in theMessages 
                set mailContents to content of eachMessage 
                try 
                    my makeNewFilemakerRecord(mailContents) 
                end try 
            end repeat 
        end tell 
    end perform mail action with messages 
end using terms from 

on makeNewFilemakerRecord(mailContents) 
    set mail_lines to paragraphs of mailContents 
    set {oldDelims, my text item delimiters} to {my text item delimiters, ":"} 
    tell application "FileMaker Pro" 
        set new_rec to create new record in database 1 
        repeat with eachField in mail_lines 
            set field_name to text item 1 of eachField 
            set field_value to text item 2 of eachField 
            set cell field_name of new_rec to field_value 
        end repeat 
    end tell 
    set my text item delimters to oldDelims 
end makeNewFilemakerRecord

Thanks for the script,

But I still have the problem that the procedure “content” doesn’t pick up all the incoming mails.

I set a script to display the contents of the selected messages (dialog), and he only display some of them? if I do view/message/plain text alternative, the contents will then show OK???

I now get the subject as argument to search on the database, and use rules to recognize the script to run on the contents. Works OK, but need to find a more flexible solution.