Sending mail email via script to specific folders

HI
Ive had a look in the forum but could not find anything, maybe some one could advise.

I am already using the email to devonthink script in mail, that places the EMI file into the global inbox.
Is it possible to create a script to send the emi to a specific group. ( a sub group of a specific database )

if this is possible
would it also be possible to have additional scripts so for example

1 for research to a particular group
1 for a specific contact or company to its own particular group

Thanks.
in advance

You can of course create additional, customized copies of the script. And the following snippet shows how to reference a certain group:


-- Ensure that the database is open
set theDatabase to open database "/path/to/myDatabase.dtBase2" 
-- Get the desired group
set theGroup to get record at "/location/of/group" in theDatabase

Hi Christian

Thanks for reply and help,
Unfortunately, I have not learnt to code as yet, thinking about learning AppleScript to help with some workflows.

I was unsure of the location for your snippet
my attempt at guessing is wrong as I get a syntax error > Expected end of line, etc. but found “"”.

one other point ~ the group name starts with a ★ emoji star in the group name - would that be an issue?

Could you advise please, have attached script ( the script I used had correct path )

Thanks again

-- Import selected Mail messages to DEVONthink Pro.
-- Created by Christian Grunenberg on Mon Apr 19 2004.
-- Copyright (c) 2004-2015. All rights reserved.

-- this string is used when the message subject is empty
property pNoSubjectString : "(no subject)"

tell application "Mail"
	try
		tell application id "DNtp"
			if not (exists current database) then error "No database is in use."
			set theGroup to preferred import destination
		end tell
		set theSelection to the selection
		if the length of theSelection is less than 1 then error "One or more messages must be selected."
		repeat with theMessage in theSelection
			my importMessage(theMessage, theGroup)
		end repeat
	on error error_message number error_number
		if error_number is not -128 then display alert "Mail" message error_message as warning
	end try
end tell

on importMessage(theMessage, theGroup)
	tell application "Mail"
		try
			tell theMessage
				set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, subject, the source, the read status}
			end tell
			if theSubject is equal to "" then set theSubject to pNoSubjectString
			tell application id "DNtp" to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string), unread:(not theReadFlag)} in theGroup

set theDatabase to open database "/path/to/myDatabase.dtBase2"
set theGroup to get record at "/location/of/group" in theDatabase

			on error error_message number error_number
			if error_number is not -128 then display alert "Mail" message error_message as warning
		end try
	end tell
end importMessage

This section…

 tell application id "DNtp"
    if not (exists current database) then error "No database is in use."
      set theGroup to preferred import destination
end tell

should be…


tell application id "DNtp"
     set theDatabase to open database "/path/to/myDatabase.dtBase2”
    set theGroup to get record at "/location/of/group" in theDatabase
end tell

Remove the lines from where you put them.

Hi Bluefrog

Thanks for help

I corrected previous, I also changed my group names as obviously did not like my star emoji and got rid of spaces in the name for the path.

it compiles correctly after a few syntax errors related to the above.
But when I run the script from mail it still places the EMI in the Global inbox

Thanks again for help, any ideas ?

I am not sure why in below the copy paste put the database line on a new line in script editor it is on. one line… not sure if that is relevant.


tell application "Mail"
	try
		tell application id "DNtp"
			set theDatabase to open database "/Users/indigosanshome/Databases/TWM.dtBase2"
			set theGroup to get record at "/TWM/MARKETING/EMAILS/BRANDS" in the database
		end tell
		set theSelection to the selection
		if the length of theSelection is less than 1 then error "One or more messages must be selected."
		repeat with theMessage in theSelection
			my importMessage(theMessage, theGroup)
		end repeat
	on error error_message number error_number
		if error_number is not -128 then display alert "Mail" message error_message as warning
	end try
end tell

on importMessage(theMessage, theGroup)
	tell application "Mail"
		try
			tell theMessage
				set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, subject, the source, the read status}
			end tell
			if theSubject is equal to "" then set theSubject to pNoSubjectString
			tell application id "DNtp" to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string), unread:(not theReadFlag)} in theGroup
		on error error_message number error_number
			if error_number is not -128 then display alert "Mail" message error_message as warning
		end try
	end tell
end importMessage


Hi Christian and Bluefrog

I had assumes that as the script compiled ok it was written ok
But I had an additional space by mistake. now corrected.

It now works

Thanks again for your help !

indigosans