Send written mail and place it in specific folder.

I am on Lion and I would like to make a script that would send an mail I just wrote (just as what would happen when I clic on the “send” button in mail) and then put it in a specific folder instead of letting him in the “sent messages” folder.

I am really new to AppleScript and have just spend one our only to try making a script send the currently opened mail and couldn’t make it work, which I feel a bit stupid about.:confused:

Here is one of the things I tried :

tell application "Mail"
	send outgoing message
end tell

I hope someone can help, and sorry for not being able to do even such a stupid thing as sending a mail.
Then of course I’d like the sent message to be put in a specific mail folder.

Thank you for your help.

If all you are looking to do is move sent messages, a Mail Rule might be the right tool for the job. Mail > Preferences > Rules.

Thank you adayzdone for your answer but no it is not just what I am trying to do.
I would like to make a script that sends the current email + puts it in a specific folder. So that when I have written an email and am ready to send it, I could, by starting my script, have it sent and put in a specific folder.
A mail rule would be good if I wanted each mail I send to be put in a specific folder, but it is not the case, I still want to be able to send some of my mail the normal way, without filing them in an other folder.
Hope I am clear enough.

I have little experience scripting Mail, so don’t expect a solution.
Identifying that outgoing message is the 1st task. I opened Mail, and ran this little script:

tell application "Mail"
	outgoing messages
end tell
--> {}

which returns an empty list. Then I clicked ‘new message’ in Mail, and ran the script again. Now I get {outgoing message id 1}. Ah! The script has to talk to “outgoing message id ”.

I googled MacScripter on “send message” and found this.
Apparently any outgoing message will first go into “Sent”, so your script will have to move it from there. Also, the message in “Sent” seems to be a copy, with its own id.

Thank you for your help alastor933, very interesting information.

So that script is more complicated to make that it seems. It’s a simple task but not simple to make.

I still don’t get how to just send the outgoing messages. it seems like outgoing messages don’t understand the command “send” (that’s what the error message says when I try “send outgoing messages”), and then I’m still stuck on the next step. This really is too advanced for me I’m afraid.

“Send” sends one message, which must be identified somehow. You cannot say “send outgoing message”, you must say “send outgoing message id ”.
This should work:

tell application "Mail"
	-- this line gets you an identifier for one outgoing message
	set myNewMessage to first outgoing message
	-- this line sends it
	send myNewMessage
end tell

Thank you but here is the error message I get :

Yes, bummer. And there are more problems: as far as AppleScript is concerned an outgoing message seems to not exist. You can ask for its id, but that is all you can get. No sending, no asking for its subject or anything. So you can never find it when it has become a ‘sent’ message.
It might be doable with UI scripting (have the script click buttons) but getting that to work is very much trial and error, so takes a lot of time.

Well I guess I’d better just forget about it then. Thank you so much for your insights. If an AppleSript guru once read this and have another idea that we haven’t thought of.