Saving email attachments from Mail to DevonThink and substituting with item link in email


There are several old conversations that discuss this but without any solution. I’m hoping that over the intervening years someone may have found a way.

Here is what I would like to do:

  • Save an attachment from an email as an individual item in DevonThink (e.g. via attachment context menu)
  • Remove the attachment from the email
  • Add a link to the DevonThink item in the email

I would be happy to do this on a per-email or per-attachment process, rather than bulk-processing many emails (although I could certainly make use of that).

At the moment, the only thing I can do is manually drag and drop the attachments to DevonThink. Then, I need to manually remove the attachments from the email in Mail > Message > Remove Attachments.

Has anyone got any working methods or suggestions?

Thank you.

1 Like

I doubt that any mail server is prepared to modify emails in situ like you propose here. One way I see:

  • Copy the content of the email to a new message
  • append the DT link to the attachment to it
  • send the new email to yourself
  • delete the original email.

This may or may not be scriptable, depending also on your email program

I find the whole idea irritating: attachments would only be accessible if the relevant DT database is available on the device you’re currently reading your email with. Which goes against the whole concept of an email server

1 Like

Thanks for your input.

Emails can be modified: Mail will strip attachments and Thunderbird adds a link to the file in the filesystem. I’m not sure how this is done, whether it’s detached on the server or the original is deleted and replaced with the updated copy of the email.

I just tried that with an e-mail containing only a single attachment (“E-Mail”/“Remove attachments”) in Mail. No apparent change. When I move away from this e-mail and back to it, the attachment is still visible, but the summary says “the attachment has been manually removed”.

Thunderbird doesn’t seem to have any scripting support (except for the default classes). So I’d probably go with the approach described before.

Intriguing … What might work, is an AppleScript that works on the the selected e-mail:

  • save the attachment(s) to a well known location
  • send them directly to DT3

the latter requires scripting the context menu, and I dont know how to do that.

  • import the saved attachments into DT3 one by one
  • for each one, retrieve the DT3 link to the newly created record
  • delete the attachments from the download folder
  • create a new outgoing message in Mail
  • set its subject to the subject of the original message
  • set its sender to the original sender
  • set its content to the original content plus the DT3 links to the attachments
  • set its recipient to yourself
  • send this message
  • delete the old message

Not trivial, but should be possible. And I’d only implement the last step if I were sure that the other ones are working as intended.

1 Like

May I ask what is the purpose of this?


To have documents in DevonThink and to retain the context and history of conversation on email. I know that I can import email into DevonThink but that is not the best way of managing active email conversations.

But what does stripping attachments and trying to modify email messages have to do with “managing email conversations” ?

1 Like

Email applications will conveniently arrange emails in conversations, which DevonThink won’t. I can also reply when needed in future and pick up the conversation with relevant contacts.

However, DevonThink is where I want to keep the documents included in those conversations as that’s what DevonThink is best at. I no longer need them in the email application where they take up significant space and reduce the email application’s performance.

Might I suggest leaving the mail as it is (including the attachment) but have a smart rule action that creates a replicant of the attachment?

That could be scriptable, but that’s something @BLUEFROG might comment on.

The idea would be:

  • upon import email
  • run script
  • check for attachment(s)
  • create replicant(s) of attachment(s) in some folder
1 Like

Thanks, this seems like a good idea for when email is imported into DT. However, for this case use I am not looking at importing email.

This isn’t exactly the same issue, but when I drag an email into DT3, I usually also drag the attached file in too (separately) - because then the entire document will show up in searches (and show the occurrences), not just display the email message. In addition to the extra step, the drawback of course is wasted space, roughly doubling storage needed for some files that are often fairly large.

The action to start a smart rule or script (like importing) is irrelevant, any other trigger like ‘Before sync’ would work as well.

It’s obvious DT is aware of the presence attachments, as the meta-data shows a paperclip and counts the number of attachments. So far, so good.

The main question for @BLUEFROG is: would creating a replicate of an existing e-mail attachment be scriptable somehow? I’ve browsed through the Applescript library and didn’t find a suitable reference, but that’s me.

If not: could this be added as a smart rule action? (Which would be a feature request).

Hence my suggestion of creating a replicate of the attachment if possible.

Yes it’s possible to replicate a file via AppleScript.

If not: could this be added as a smart rule action? (Which would be a feature request).

There already is a Replicate action in smart rules.

I feel we’re communicating on different ‘wavelengths’ here :slight_smile:

Isn’t an attachment or aren’t several attachments an integral part of one e-mail record?

Replicating an e-mail record including the attachment is possible, but how does one separate the attachment from the e-mail and replicate only that attachment?

See importing emails with attached PDF files


This is certainly getting nearer, but if I understand the script correctly this duplicates the attachment and doesn’t replicate it, as DT seems to import the attachment:

tell application id "DNtp" to import theAttachment to theGroup

Which will create a new record and not a replicate of the attachment. Might it be that attachments aren’t stored within the eml as a separate record, but as an integral part of the eml record?

Attachments are only part of the .eml file, they’re not imported on their own.

Right, that clears up the main question, and perhaps the confusion :slight_smile:. If the attachments is part of the eml it’s obviously not possible to create a replicate of the attachment only.

But could this somehow be possible in a future release of DT?

Attachments frequently are a separate document that can be related to the e-mail, but not necessarily. In the latter case e-mail just happened to be the medium that was used to transport a file (the attachment). Loosing the relation between the e-mail and attachment is undesirable, but looking through e-mails to find a specific file is also undesirable.

The idea behind replicating the attachment only, is that attachments needn’t be present twice in a database or several databases as it increases unnecessary redundancy. This is of course why replicates exist (and is one of the reason that makes DT such a nice product IMO).

Perhaps DT could create two or more UUIDs per e-mail, that refer to the e-mail and one or more attachments, but keeps them related while viewing an e-mail. The UUID of the attachment(s) can be replicated (or duplicated if need be) to another group.

Replicating doesn’t support internals of files, it’s highly unlikely that this will ever be possible. Importing the attachments on their own (like the above scripts does or the scripts in the Scripts menu extra for Apple Mail) are the only options currently.