Send by e-mail - automatically send each document in folder

Hi, periodically I have to send my accountant all a whole bunch of documents. Now, she is using an online service that requires me to send 1 document / attachment per e-mail. Say there are 25 docs, I have to manually right-click 25 times each consecutieve doc and select Send by email, enter the addrss in Mail and click Send.
Highly inefficiënt.

Is there a way to have this automated fo all files in a folder? I searched for a script buy can’t find what I need. My knowledge of any scripting language is close to nil…

Any suggestions highly appreciated!

Thnx,
HJ

Here’s a sample script

tell application id "DNtp"
	repeat with theGroup in (get selection)
		repeat with theRecord in (children of theGroup)
			set theName to name of theRecord
			set thePath to path of theRecord
			my MailRecord(theName, thePath)
		end repeat
	end repeat
end tell



on MailRecord(theName, thePath)
	
	tell application "Mail"
		
		set theFrom to ""
		set theTos to {""}
		set theCcs to {}
		set theBccs to {}
		
		set theSubject to "" & theName
		set theContent to ""
		
		set theMessage to make new outgoing message with properties {sender:theFrom, subject:theSubject, content:theContent, visible:false}
		tell theMessage
			repeat with theTo in theTos
				make new recipient at end of to recipients with properties {address:theTo}
			end repeat
			repeat with theCc in theCcs
				make new cc recipient at end of cc recipients with properties {address:theCc}
			end repeat
			repeat with theBcc in theBccs
				make new bcc recipient at end of bcc recipients with properties {address:theBcc}
			end repeat
			make new attachment with properties {file name:thePath} at after last paragraph
			delay 1
			send
		end tell
	end tell
end MailRecord
1 Like

Thnx DTLow. I’ve created a script, put it in a newly created folder ~/Users/hj/Library/Application Scripts/com.devon-technologies.think3/Menu/Mail

I run it, and then nothing happens. If I run it from Script editor, having 3 docs selected in a DevonThink-group, the replies in ScrEditor are:
tell application “DEVONthink 3”
get selection
→ {content id 147696 of database id 5, content id 148062 of database id 5, content id 147992 of database id 5}
count every child of content id 147696 of database id 5
→ 0
count every child of content id 148062 of database id 5
→ 0
count every child of content id 147992 of database id 5
→ 0
end tell

The script then stops; no mails are created nor send.

Any thoughts?

Henk-Jan

Try selecting groups instead of individual docs

The script could use selected files, but you indicated “all files in a folder”
To use selected files, remove theGroup line., and use

repeat with theRecord in (get selection)

OK, thnx. Selection of the Group does not make a difference. Not sure if my first problem description was clear enough.

Anyway, I tried to simplify the script, now this works:

tell application id “DNtp”

repeat with theGroup in (get selection)

set theName to name of theGroup

set thePath to path of theGroup

my MailRecord(theName, thePath)

end repeat

end tell

on MailRecord(theName, thePath)

tell application “Mail”

set theFrom tofrom@from.com

set theTo toto@to.com

set theSubject to “” & theName

set theContent to “”

set theMessage to make new outgoing message with properties {sender:theFrom, subject:theSubject, content:theContent, visible:false}

tell theMessage

make new recipient at end of to recipients with properties {address:theTo}

make new attachment with properties {file name:thePath} at after last paragraph

delay 1

send

end tell

end tell

end MailRecord

So, many thanks, for directing me into the right path!

HJ