You can do this with a little bit of code in Outlook and a little bit of code in Emacs.
First, if you're using Outlook 2007 you'll need to enable Outlook URLs with a registry addition. Instructions and the registry file can be found here courtesy of David Tan.
Next, this macro can be added to Outlook and will get the GUID of the current email message, create a Org-Mode link and deposit it into the clipboard.
'Adds a link to the currently selected message to the clipboard
Sub AddLinkToMessageInClipboard()
Dim objMail As Outlook.MailItem
Dim doClipboard As New DataObject
'One and ONLY one message muse be selected
If Application.ActiveExplorer.Selection.Count <> 1 Then
MsgBox ("Select one and ONLY one message.")
Exit Sub
End If
Set objMail = Application.ActiveExplorer.Selection.Item(1)
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
doClipboard.PutInClipboard
End Sub
As koushik noted in the comments, the doClipboard.SetText
part can be expanded to differentiate between different item types:
If objMail.Class = olMail Then
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
ElseIf objMail.Class = olAppointment Then
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MEETING: " + objMail.Subject + " (" + objMail.Organizer + ")]]"
ElseIf objMail.Class = olTask Then
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][TASK: " + objMail.Subject + " (" + objMail.Owner + ")]]"
ElseIf objMail.Class = olContact Then
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][CONTACT: " + objMail.Subject + " (" + objMail.FullName + ")]]"
ElseIf objMail.Class = olJournal Then
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][JOURNAL: " + objMail.Subject + " (" + objMail.Type + ")]]"
ElseIf objMail.Class = olNote Then
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][NOTE: " + objMail.Subject + " (" + " " + ")]]"
Else
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][ITEM: " + objMail.Subject + " (" + objMail.MessageClass + ")]]"
End If
Almost there, add this little bit of lisp to your emacs lisp directory to enable Outlook links.
;;; org-outlook.el - Support for links to Outlook items in Org
(require 'org)
(org-add-link-type "outlook" 'org-outlook-open)
(defun org-outlook-open (id)
"Open the Outlook item identified by ID. ID should be an Outlook GUID."
(w32-shell-execute "open" (concat "outlook:" id)))
(provide 'org-outlook)
;;; org-outlook.el ends here
And lastly, update your .emacs file to include the Outlook link code. Just add this somewhere after org-mode is setup.
(require 'org-outlook)
Now you can call the macro (I added it to my toolbar in Outlook for quick access) and you can quickly create a link to the email in Emacs.
One gotcha, GUID's change when you move a message between document stores, so if you get the GUID to the message while it's on your Exchange server and then move it to your local PST file the link will change. Move the message before you get the GUID.
4This is great, thank you! One simplification: I didn't mess with the registry to enable Outlook URLs, instead I just changed the w32-shell-execute call to this: (w32-shell-execute "open" "C:/Programme/Microsoft Office/Office12/OUTLOOK.EXE" (concat "/select " "outlook:" id) – Christian Berg – 2010-01-26T15:17:31.090
I got a unknown type error for DataObject. After trying out various options such as add reference to Microsoft Forms which was not available for adding, and others I came across https://www.excelforum.com/excel-programming-vba-macros/338020-dataobject-and-cliboard.html and added a dummy userform and it started working
– Miserable Variable – 2018-10-31T21:47:43.903Any pointers to a macOS equivalent? – Paul Bissex – 2019-05-08T12:32:54.817
2To solve the DataObject type error, the following worked for me. In the macro editor, go to Tools->References. Click browse, select the file
C:\Windows\System32\fm20.dll
and press OK. – Hugo Ideler – 2019-05-09T18:40:17.947@HugoIdeler: Note that on x64 systems, the location of the dll is C:\Windows\SysWOW64 – Thomas – 2019-09-12T13:04:24.370
1Thanks for this answer. I found out that I somewhat needed to create an empty form to prevent compilation error on undefined DataObject. – Laurent' – 2011-11-05T13:24:12.670
@ChristianBerg: I'm using Outlook 2003, so maybe I can have hyperlinks without bothering with the registry, but your simplification did not work, Outlook was unable to find the URL. And every time I clicked on a link in Emacs, a new outlook-process was started. So I sticked to the great solution by user259... – Keks Dose – 2012-01-26T13:56:55.147
This is fantastic ! Thank you for providing this solution. I tried it with outlook 2007 with the registry tweak and it worked like a charm ! I found 1 issue if I ran the macro when I had a meeting invite / appointment selected. The code threw an exception. Since I use it only on the inbox I solved this by Dim objMail as Object instead of MailItem - however this may not be the right solution since the code could still fail if the item selected doesn't have Subject/ SenderName members. The code could probably check if the selected item is of proper type and provide a MsgBox if it is not. – koushik – 2012-02-22T15:23:52.383
1
I "scratched this itch" of mine a bit more as I had to record links to some appointments for working on related items (so I can refer ot info / attachments therein or reply all when I have updates etc). Now this can export mails, calendar items, contacts, notes, journal entries and at least will not fail when invoked on other entries. The modified code is at http://pastebin.com/gNWLVNRk (I can provide a diff if it would help - though I don't know how to make on in VBA). I didn't have to make any other change (emacs-side or regsitry) for this to work on my end. HTH.
– koushik – 2012-07-23T13:50:30.927@koushik: Thank you for your great script. Where do you past those links? The syntax [[url][description]] is not recognized by outlook... – Simon – 2013-08-01T12:54:24.303