email from filename

I am looking for help with an Applescript to send an email based on a text file filename. Ideally I would like to apply said script to a folder action.

For example, I name a text file john@doe.com and save it in a folder named email. The Applescript then copies the filename and pastes that filename into OS X mail’s TO: . Then the Applescript attaches the text file to the email. Sends the email. The deletes the original file and waits to repeat the action over again.

I don’t know Applescript very well and would appreciate any help. Also, do you recommend any specific books I can purchase to help me learn.

Thanks!

Fletch

Very good tutorials here at MacScripter.net

E-mail script:

on run
	processFile(choose file)
end run

on open theObject
	processFile(item 1 of theObject)
end open
---------------------------
on processFile(aFile)
	set fNameAndExt to name of (info for aFile)
	set fExt to name extension of (info for aFile)
	set fName to text 1 thru -((count fExt) + 2) of fNameAndExt
	
	tell application "Mail"
		set newMail to make new outgoing message at end of outgoing messages with properties {visible:true}
		tell newMail
			make new to recipient at end of to recipients with properties {address:fName}
			tell content of newMail to make new attachment at after last paragraph with properties {file name:aFile}
		end tell
	end tell
end processFile

You can easily convert this script to a folder-action.

Hope it helps,
ief2

Thanks very much for the help! I’ll let you know how it works out!