I use Office 365 (OWA - Outlook Web App) for my email. I have posted a number of times about my biggest need for software automation – importing individual emails in Outlook Web to DT3 along with their attachments.
While my past solutions have worked, somehow I may have overlooked the simplest solution of all. Or maybe the interface in OWA changed at some point and I had not noticed.
In any event, next to each message in OWA are 3 dots - in that menu there is an option to Download the message to an .eml file in your Downloads folder:
I set up Hazel to process emails to my Downloads folder via a script (adapted from an old post - thank you @BLUEFROG - my version uses the group selector rather than a specific import location ):
tell application id "DNtp"
set newFile to import theFile to display group selector
set {recName, recURL} to {name, reference URL} of newFile
if (exists newFile) then tell application "Finder" to delete theFile
end tell
This works very well so all I need to do is to click Download on a message and then the Group Selector shows up to let me choose where to put the message within my set of DT3 databases.
If there are attachments within the email they remain embedded in the original email inside DT3 so the messages are thus retained precisely in native email form. However often it is desirable to place those messages within a subgroup. I adapted this script (which I run from Keyboard Maestro) to do just that - it mostly comes from a post on this Forum but unfortunately I do not remember who authored it (thank you whoever it was - I suspect @cgrunenberg )
tell application id "DNtp"
set theSelection to the selection
set tmpFolder to path to temporary items
set tmpPath to POSIX path of tmpFolder
with timeout of 14400 seconds
repeat with theRecord in theSelection
if type of theRecord is unknown and path of theRecord ends with ".eml" then
set theRTF to convert record theRecord to rich
set theURL to reference URL of theRecord
set newGroup to false
try
if type of theRTF is rtfd then
set thePath to path of theRTF
set theGroup to parent 1 of theRecord
set theName to name of theRecord
set theModificationDate to the modification date of theRecord
set theCreationDate to the creation date of theRecord
set theAdditionDate to the addition date of theRecord
tell text of theRTF
if exists attachment in attribute runs then
tell application "Finder"
set filelist to every file in ((POSIX file thePath) as alias)
repeat with theFile in filelist
set theAttachment to POSIX path of (theFile as string)
if theAttachment does not end with ".rtf" and theAttachment does not end with ".png" then
try
with timeout of 7200 seconds
-- Importing skips files inside the database package,
-- therefore let's move them to a temporary folder first
set theAttachment to move ((POSIX file theAttachment) as alias) to tmpFolder with replacing
set theAttachment to POSIX path of (theAttachment as string)
tell application id "DNtp"
if newGroup is false then
set newGroup to create record with {name:theName, type:group, modification date:theModificationDate, creation date:theCreationDate, addition date:theAdditionDate} in theGroup
end if
set importedFile to import theAttachment to newGroup
set URL of importedFile to theURL
set the modification date of importedFile to theModificationDate
set the creation date of importedFile to theCreationDate
set the addition date of importFile to theAdditionDate
end tell
end timeout
end try
end if
end repeat
end tell
if newGroup is not false then
tell application id "DNtp"
move record theRecord to newGroup
end tell
end if
end if
end tell
end if
on error msg
display dialog msg
end try
end if
delete record theRTF
end repeat
end timeout
end tell
on makeDate(dateString)
set theDate to date dateString
end makeDate
All told this works really well for importing specific email messages and immediately filing them in the relevant Group in DT3. Since my desktop and laptop computers both sync DT3 to a common WebDav sync store on my Synology, it works equally well from either the desktop or laptop computer.