Use Folder actions to watch and email new email files

I’m trying to create a script that use Folder Actions which will watch the Sent Email folder (of Tiger Mail), and upon a user sending an email it sees the new email file copied there and then sends that file to a specified email account.

So far it will generate the email with the Subject and To but does not add the attachment like it seems it should. Here’s the code:

on adding folder items to this_folder after receiving added_items
	
	tell application "Mail"
		set newMessage to make new outgoing message with properties {subject:"Email from me" & return & return}
		
		tell newMessage
			set visible to true
			make new to recipient with properties {name:"My name", address:"my@email.net"}
			tell content
				make new attachment with properties {file name:added_items} at before the first paragraph
			end tell
		end tell
		activate
	end tell
end adding folder items to

Since the variable added_items represents a list, Jim, you’ll need to either extract its first item:

on adding folder items to this_folder after receiving added_items
	tell application "Mail" to tell (make new outgoing message with properties {subject:"Email from me", visible:true})
		make new to recipient with properties {name:"My name", address:"my@email.net"}
		make new attachment with properties {file name:item 1 of added_items} at before first paragraph
	end tell
end adding folder items to

… or iterate through the list, to attach every item that it contains:

on adding folder items to this_folder after receiving added_items
	tell application "Mail" to tell (make new outgoing message with properties {subject:"Email from me", visible:true})
		make new to recipient with properties {name:"My name", address:"my@email.net"}
		repeat with current_item in added_items
			make new attachment with properties {file name:current_item} at before first paragraph
		end repeat
	end tell
end adding folder items to

Hey Kai, excellent, that works! That is exactly what I needed. Thanks a bunch!

Nice script, could come in very handy.

Thanks

Ohhh, an unexpected and ugly side effect… This script runs on a DP Xserve which hosts the user space for our company (all users log in from their Mac desktops to their user space on the xserve). It is intended to use this script to monitor outgoing emails for about 6 people. The problem is, though, that adding just three instances of Folder Actions to the Xserve causes the “System Monitor” usage to skyrocket and eventually peg the machine slowing it to a crawl.

Is this a known issue with Folder Actions?