I found many topics on this forum where people try to find a reliable way of importing all emails into DEVONthink automatically to handle them in the inbox there using its advanced categorization features. But I couldn’t find any solution that seemed to work reliably and was easy to maintain at the same time. After trying out a lot of different approaches and seeing most of them fail, I finally found a solution that works for me which I want to share.
Prerequisites
My solution has two caveats though:
- You need an always-on Mac running as a “server”, such as a Mac mini. Otherwise, Apple Mail rules won’t work reliably.
- And you need a DEVONthink seat in your license (thankfully, all licenses come with 2 seats = 2 devices – so if you’re using DT on only one Mac, your existing license should do – otherwise you have to buy one for currently $99).
If none of these hold you back (like in my case, because I already use a Mac mini as a media server + for backups), then read on to learn about how my solution works. It’s based on Apple Mail rules and a single line of code adjustment in DEVONthinks’ pre-shipped AppleScript files.
Step 1: Setting up DEVONthink on the always-on Mac
- Download & install DEVONthink Pro on the always-on Mac (adjust import preferences if needed)
- Install the additional tools you need (like OCR) and make sure to include the Apple Mail plugin & scripts
- Setup the Sync for the database you want to import the emails to (out of scope for this guide)
Step 2: Setting up Apple Mail
- Set up one or multiple email accounts you want to forward emails from to DEVONthink in Apple Mail
- Create a folder (via + button when hovering over account name) in one of your email accounts and name it exactly
DEVONthink
(that’s where we’ll move emails as a backup) - Create two subfolders inside
DEVONthink
(via right-click on the folder > “New mailbox…”) and name themIncoming
andOutgoing
(we’ll also import sent emails, so let’s keep them separate) - Turn on the Apple Mail plugin (in Apple Mail > Settings > General tab > Manage plugins)
- Change the email accounts “Description” field in Settings > Accounts you created the
DEVONthink
folder in toMail Hub
(or keep description in mind, you’ll need it later)
Step 3: Adjusting DEVONthinks’ AppleScript files
- Open Apple Mail settings, go to the Rules tab, and press “Add Rule”
- In the “Perform the following actions” section, choose “Run AppleScript”
- In the values dropdown for “Run AppleScript”, select “Open in Finder” (you can cancel the rule setup dialog in Mail for now)
- Duplicate the script “Mail Rule - Add messages to DEVONthink” to import the email as an
.eml
file (including attachments) – or if you prefer to save import the attachments as separate documents, duplicate “Mail Rule - File messages & attachments” instead - Rename the duplicated script to “Send to DEVONthink + move to DT-Incoming folder”
- Double-click the renamed script to open it in the “Script Editor” app
- Add the following line right before the last
end repeat
towards the end of the file and save the file (via Cmd + S):
set mailbox of theMessage to mailbox "DEVONthink/Incoming" of account "Mail Hub"
(If you didn’t rename your email accounts description to Mail Hub
before, adjust it here.)
The result should look like this:
- Now go back to the Finder window with the scripts (or repeat until step 3), this time duplicate the new script we just created
- Rename the duplicated script to “Send to DEVONthink + move to DT-Outgoing folder” (note the
Sent
at the end) - Double-click the renamed script and in the line we added, change
DEVONthink/Incoming
toDEVONthink/Outgoing
and save the file (Cmd + S)
Step 4: Setting up the Apple Mail rules
- Open the settings in the Mail app, navigate to the “Rules” tab, and press “Add Rule” (if it was open already, you can skip this step)
- Change the description to
Incoming to DEVONthink
- Select
any
above the conditions section - Set the first condition to
To
,is equal to
and your main email address as the value - Add another condition for each alternative email address you want to forward (if any)
- In the “Perform” section, set the action to
Run AppleScript
and select theSend to DEVONthink + move to DT-Incoming folder
(note the ‘Incoming’!)
The end result should look like this:
- Press “OK” and select “Do not apply” for now so we can finish the setup without delays
- Repeat steps 1 to 7, but 3 changes: a) name it “Outgoing to DEVONthink”, b) select
From
for the condition type, and c) select theSend to DEVONthikn + move to DT-Outgoing folder
(note the ‘Outgoing’!) - Press “OK” and select “Do not apply” again for a more controlled migration
Permissions, Validation & Initial Migration
- To test things out, and also to get any Apple permission dialogs, right-click on any email you received in your main account and press “Apply Rules” at the bottom
- On first usage, this should ask you for permissions to access DEVONthink – give all permissions asked for
- The rule might not have worked on first try (due to lacking permissions), so revert any changes (if anything happened) and repeat step 10
- Validate that the email was moved to the
DEVONthink/Incoming
folder and that it was sent to DEVONthink, too (if not, something went wrong, check the rule & script) - Now right-click an outgoing email you’ve sent yourself and choose “Apply Rules”
- Validate that the email was moved to the
DEVONthink/Outgoing
folder and that it was sent to DEVONthink, too (if not, something went wrong, check the rule & script) - Now, to test if this works with new emails, ask someone to send you a test email (or use an email address you haven’t configured) – this email should land in
DEVONthink/Incoming
and DEOVNthink app automatically (wait a few seconds until Apple Mail gets it) - Next, test if this works with sent emails, by sending a test email from another device to a friend – this one should land in
DEVONthink/Outgoing
and DEVONthink app automatically - When these things worked as expected, you can now select all mails in all your folders (Cmd + A), right-click and press “Apply Rules” to apply the rules to all your emails, or start with just a few to further validate things work as expected
Now just keep your Apple Mail app and DEVONthink open on this Mac and things should work.
Please note that I’m taking no responsibility if anything breaks in the process and you lose any data. I’ve tried to come up with a safe approach, keeping the emails on your Mail server as a backup. Also, only one line adjustment in the scripts to not mess around.
While I tested this setup extensively, I did not use it long term yet, so I will report if I run into any issues, but I wanted to share before I forget the details. If you run into any issues or have suggestions for improving the workflow, feel free to share so we can learn all together.