Send received fax/pdf as attachment by mail and erase it afterwards

Here is a script I have to watch the Fax-folders content and send the files as attachment by mail.
Somehow I cannot get it work, as it stops in line >set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent & return & return, recipient:theRecipient}
Any suggestions or corrections are welcome! Thanks!

tell application “Finder”
set theHome to (path to home folder) as reference
set theFolder to item “Fax” of theHome
set theCount to count of items in theFolder
end tell

if theCount > 0 then
repeat with theLoop from 1 to theCount
set theFile to the item theLoop of theFolder
set theString to the (item theLoop of theFolder) as string
set theBody to the POSIX path of theString
send_mail(theBody)
delete theFile
end repeat
end if

on send_mail(theBody)
tell application “Mail”
set theAddress to “faxes@welkam.co.jp”
set theName to “FAX”
set theRecipient to theAddress
set theSubject to “New Fax received!”
set theContent to (theBody as string)
set theAttachment to theContent
set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent & return & return, recipient:theRecipient}
tell theMessage
set visible to false
tell content
make new attachment with properties {file name:theAttachment} at after the last paragraph
end tell
make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
end tell
send theMessage
end tell
end send_mail

Model: Mac Pro
AppleScript: 2.0.1
Browser: Safari 525.20.1
Operating System: Mac OS X (10.5)

Hi,

you’re defining the recipient twice, it doesn’t work in the make new outgoing message line.
To avoid timing problems I recommended to use a controlled delay.


set FaxFolder to alias ((path to home folder as text) & "Fax:")
tell application "Finder" to set theFaxes to files of FaxFolder

repeat with oneFax in theFaxes
	set POSIXFax to POSIX path of (oneFax as text)
	send_mail(POSIXFax)
	do shell script "/bin/rm " & quoted form of POSIXFax
end repeat

on send_mail(theBody)
	tell application "Mail"
		set cnt to (count outgoing messages)
		set theAddress to "faxes@welkam.co.jp"
		set theName to "FAX"
		set theSubject to "New Fax received!"
		set theMessage to make new outgoing message with properties {visible:false, subject:theSubject, content:theBody & return & return}
		tell theMessage
			tell content to make new attachment with properties {file name:theBody} at after the last paragraph
			make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
			send
		end tell
		repeat until (count outgoing messages) is cnt
			delay 1
		end repeat
	end tell
end send_mail

Note: the reference coercion of an alias is useless :wink:

Hi Stefan,

Thanks for your quick reply!
After endless search, I found this http://murphymac.com/files-mailed-magically-when-dropped-in-a-finder-folder/
and it works for me very well. I just had to copy paste it into an existing apple script and rename it, because of those permission problems in Leopard.
Thanks a lot!