Integrating Devonthink with an email program

Apple Mail no longer seems to permit scripts to transfer mail and attachments to Devonthink.

I read on this site as much as I can and it does not seem that there is a solution.

Airmail does not seem to allow attachments to be eported with the emails.

Does anyone know of an email program that would work with Devonthink.

I used to be able to use Devonthink to serve as a very good database for all my emails going back for a long time, which is really important for me as my work regularly requires me to go back in time.

Any help would be greatly appreciated

1 Like

I use an applescript to import mail to Devonthink from Apple Mail
It uses the Devonthink supplied script Add message(s) & attachments to DEVONthink.scpt
and I added a Devonthink mailbox as the trigger

set MailScript to (load script "/Users/DTLow/Library/Scripts/Applications/Mail/Add message(s) & attachments to DEVONthink.scpt")
tell application id "DNtp" to set theGroup to preferred import destination
tell application "Mail"
	set theFolder to (POSIX path of (path to temporary items))
	set TheMessages to (messages of mailbox "Devonthink" of account "iCloud")
	repeat with theMessage in TheMessages
		MailScript's imPortMessage(theMessage, theFolder, theGroup)
		delete theMessage
	end repeat
end tell

Do you add this to the devonthink script at the end ? Can you put the entire script up here ? I am not familiar with writing scripts . I have spend so much time researching this and have been totally unsuccessful. Most of the posts here on this subject are outdated and no one has posted currently a definitive solution , though it seems people want a solution.

Outlook has had this problem as a while. My workaround is to save the email (with its attachments) into the global DT inbox and then move it to wherever you want. I’ve not really used Apple Mail in a while, but presume you could do the same thing.

I posted my entire script
The first line “Load…” loads the Devonthink script which is the most important code

What makes you think that? Apple removed support for Mail plugins in Sonoma, scripting works as well or bad as it always did.

1 Like

Well, I dont see access to script in Mail and when i try to run the devonthink script to collect emails and attachments nothing happents. I saw a reference to this issue in December 2023 in a post in this group.

Ok will try it this week end…Thx

Neither do I. But it’s present in Script Editor.

More detail might be helpful, like describing step by step what you’re doing. Did you check that DT is allowed to automate Mail? And is anything logged to DT’s protocol window?

Read DEVONthink’s Help > Tutorials > Handling Email.

2 Likes

I am not familiar with the programming:
Where would I have to modify this to take into account my own set-up. Can you indicate where I would have to modify your script . Obviously you are not aware of my set up . The location of my script file is a bit different. I can change that. Anything else >

Before you modify a script, you should try to figure out why the ones included with DT do not work in your case. Answering the questions I asked might help with that.

[quote=“chrillek, post:12, topic:80152”]
Before you modify a script, you should try to figure out why the ones included with DT do not work in your case. Answering the questions I asked might

When I run the script from devonthink , nothing happens…no error msg either

This is the devonthink script

Mail Rule - File messages & attachments

– Created by Christian Grunenberg on Fri May 25 2012.

– Copyright (c) 2012-2020. All rights reserved.

– POSIX path of destination database. Global inbox is used if not specified.

property pDatabasePath : “”

– This string is used when the message subject is empty

property pNoSubjectString : “(no subject)”

using terms from application “Mail”

on perform mail action with messages theMessages for rule theRule

– Location of destination groups.

set pMessageLocation to “/” & (name of theRule)

set pAttachmentLocation to pMessageLocation & “/Attachments”

tell application id “DNtp”

if pDatabasePath is “” then

set destination_database to inbox

else

set destination_database to open database pDatabasePath – Ensure that the database is open

end if

set message_group to create location pMessageLocation in destination_database

set attachment_group to create location pAttachmentLocation in destination_database

end tell

tell application “Mail”

set theFolder to (POSIX path of (path to temporary items))

repeat with theMessage in theMessages

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”

set theRecord 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 message_group

perform smart rule trigger import event record theRecord

end tell

repeat with theAttachment in mail attachments of theMessage

try

if downloaded of theAttachment then

set theFile to theFolder & (name of theAttachment)

tell theAttachment to save in theFile

tell application id “DNtp”

set theAttachmentRecord to import theFile to attachment_group

set unread of theAttachmentRecord to (not theReadFlag)

set URL of theAttachmentRecord to theSender

perform smart rule trigger import event record theAttachmentRecord

end tell

end if

end try

end repeat

end try

end repeat

end tell

end perform mail action with messages

end using terms from

Asking again:

Did you read the tutorial I pointed you to?

Did you read the tutorial I pointed you to?

Yes… here is where i got to using the import function described:
DEVONthink has built-in email archiving for Apple Mail and Outlook.

Open View > Import and open the email client in the Emails section.

I COULD NOT FIND THE EMAILS SECTION WHEN I CLICKED ON IMPORT AND NOT SURE WHAT YOU MEAN BY EMAIL CLIENT

Yes , I tried the script approach and tried to create a rule in mail.
I dont think i put in the parameters correctly but i didnt see it work.
Assume I just want to back up the entire mailbox. What criteria do I put in ? I selected any emails containing my name on my email address in the hope of capturing all emails i received and sent.
I want it all to go into a database called emails, I have it opened and have told Apple Mail rules to run the devonthink script to add emails and attachments.
What am I doing wrong ?

Did you check that DT is allowed to automate Mail? And is anything logged to DT’s protocol window?

Where can see if that is allowed ?

System preferences/privacy/automation