Smart rule: Send mail with

Is there an example of such a script somewhere? Unfortunately I am actually too incapable of writing this myself … :frowning: … Thank you so much!

For Apple Mail DEVONthink uses internally this handler which could be used in a smart rule script too:

on sendMail(theFiles, theBody, theSubject, theReceivers, sendNow)
	tell application id "com.apple.mail"
		if NOT sendNow then activate

		set theAliases to {}
		repeat with theFile in theFiles
			set theAliases to theAliases & (theFile as POSIX file)
		end repeat
		
		tell (make new outgoing message with properties {subject:theSubject, visible:NOT sendNow, content:theBody, message signature:missing value})
			tell content
				repeat with theAlias in theAliases
					try
						set theAttachment to make new attachment with properties {file name:theAlias} -- at after last paragraph
					end try
				end repeat
			end tell
			
			repeat with theReceiver in theReceivers
				make new to recipient at end of to recipients with properties {address:theReceiver}
			end repeat
			
			if sendNow then send
		end tell
	end tell
end sendMail

Thanks a lot, i’ll try it!

Hi, thanks for the script. I get the following error:
14:59:43: Rechnung an ### on performSmartRule (Fehler -1708)

Did I configure it the right way?

Welcome @coffein

What is the code in the script?

Exactly the one cgrunenberg posted…

I suppose that you’re using the same script twice. First in the “execute embedded script” action, then in the “send email” action.
Or what exactly is the embedded script in the first action doing?

You can’t use the script posted here as-is. It would need to be called in an on performSmartRule handler and specific code would need to be added to call it properly.

Note: In it’s current state, it would send one email per file. Is that what you expect?

Furthermore, I’m not sure that I understand what you want to achieve. If you just have a bill as a record in DT3, you could probably simply send it with the “send email” action.
If, however, you use Christian’s script (the one starting with “onSendMail(…” as embedded script in the first action – that’s bound to fail. Scripts in actions need an “on performSmartRule” handler (cf. the documentation on “Automation”).

Thank you for your answers. This is what I want to achieve:
My Scanner scans a bunch of invoices and adds it after OCR in my DT-database. Now I want DT to automatically send the PDF to CANVAS (accounting-saas).

But I think this goes way over my skills :frowning:

Where can I find the automation-documentation?

For help on automation, click on “Hilfe” (Help) in the menu, select the 2nd entry (“DEVONthink 3 Hilfe”). Look for “Automation” in the help window (at the bottom left, if I remember correctly).

For everything else: You might have more success of getting help here if you’d describe your goals and your experiences/problems in achieving them more detailled.

I guess that you’re talking about “Candis” (https://www.candis.io/), not “CANVAS”?

If I understand their description correctly, you’ll just have to send an e-mail with the PDF as attachment – which is what the “Send by e-mail” context menu in DT3 does.

Did you try to right click on one of the scanned files and select “Send by e-mail” from the context menu (“Per E-Mail senden”)? What happened? Did you get an error message, did the file arrive correctly in Candis? If that works, it should be easily automated. If not, you’ll have to work out first how to send e-mails with PDF attachment to Candis.

And, by the way, if you feel more comfortable talking about all this in German: there’s German sub-forum here, too.

Hi chrillek,

many thanks. Yes, I could use the german subforum. But as the thread-starter had the same problem about attaching files to e-mails via script I thought I could just join in.

Of course, it is Candis :grimacing:, sorry about the confusion. And of course the ”Send by E-Mail« will probably work. I could also drag & drop the selected files at candis in the browser. But that’s a very manual way and I often just press the scan-button and forget this step.

I will look into the documentation, maybe I can find a solution for my laziness :wink:

Please see this thread. I posted an embeddable script that can be used to send records attached to e-mails from a smart rule.

Background: My assumption that DT3 does the same things in the context menu’s “send e-mail” and the smart rules’s action “send e-mail” was unfortunately not correct. The action only sends the DT3-internal reference instead of an attachment. That is not very helpful if one wants to forward documents to someone else from a smart rule. It’s also counterintuitive in my opinion. At least the action should get another name and its behavior should be clearly documented.