Process your emails – an Outlook plugin

I got a nice email last week from someone asking why I never made the “triage” Outlook plugin I mentioned last year available as I have with other bits of code. The short answer was obviously because I never got round to finishing it! :-)

However, the idea feels a bit more topical at the moment so I think it is worth revisiting.

The aim was to create something that would let me process my emails in Outlook Mobile (the cut-down version of Outlook you get on Windows Mobile PDAs and smartphones).

“Processing”, rather than doing emails is an idea that I hear people mention more often since Merlin Mann’s brilliant Inbox Zero talk started doing the rounds as a Google video. I’m even hearing other people use it as a phrase from time to time! I used to call it “triaging” my email, but I think “processing” is actually a better term. Either way, the idea is that I want to be able to go through my inbox as quickly as possible – doing something with each one so that I can finish up with an empty inbox.

Inbox ZeroIt doesn’t mean doing everything right away – just putting the information in it’s right place. If it’s an email asking me to do something, the right place for the email is in my Task List, not my Inbox. If it’s an email telling me about a meeting or appointment, then the right place for the email is in my Calendar. If it’s an email containing information that I need to keep for future reference, then the right place for it is in my wiki.

Mobile phones seem like an ideal tool for processing email, as it’s something that you can do when you have a few spare minutes and without having to do a lot of text entry or other input. Rather rely on manual (and slow!) copy-and-pasting, I wanted Outlook Mobile to be able to move my emails around like this for me. This was the idea of the plugin…

If you are interested in the pain of writing MAPI plugins in C++, read on. If you are… erm… normal – then the short version is that I tidied up the code and made it available.

As I mentioned when I originally wrote the plugin, the idea was to use IContextMenu to add new menu items to Outlook’s context menu. Once you’ve got that bit working, most of it is pretty straightforward. The only other tricky bit is writing the MAPI code to get the information you want out of the email.

There is a nice intro to Getting Started with MAPI on the Windows Mobile Team Blog (annoyingly written about five months after I spent a few nights trying to get my head around it with virtually no doc! :-) ), which tells you how to get simple short values out of emails using MAPI – like the date/time an email was sent.

Getting longer properties – like the body of the email – is more complicated, and isn’t something that was covered in the blog post. It was asked for a few times in the comments so I’ve copied a simplified snippet of code below in case it is helpful to people.

// starting with pMsg - an IMessage, as it's fairly straightforward 
//   to get to that bit

// need a different method to get larger properties, like the email body
LPSTREAM        pStmBody    = NULL;
STATSTG         statstg     = {0};
DWORD           cbRead      = 0;

// open a stream that we will use to get the email body
pMsg->OpenProperty(PR_CE_MIME_TEXT, 
                   &IID_IStream, 
                   STGM_READ, 
                   NULL, 
                   (LPUNKNOWN*)&pStmBody);

// we successfully opened the stream
// before getting data out of it, we use stat to ask how
//  much space we will need
memset(&statstg, 0, sizeof(statstg));
pStmBody->Stat(&statstg, STATFLAG_NONAME);

int msgsize = statstg.cbSize.LowPart + 1;

// allocate space in the string's used to store the body
char* szEmailBody = (char*)malloc(sizeof(char) * msgsize);

// read data from the stream into our char array
hr = pStmBody->Read((void*)szEmailBody, msgsize, &cbRead);

// finished with the stream
pStmBody->Release();

As I’ve mentioned before, when you get the PR_CE_MIME_TEXT contents of a mail from a POP3 account, you get the MIME version of the email. It’s still readable, you just get a bunch of headers at the top. It’s a pain, but not bad enough that I’ve ever been bothered to write the code to clean that bit off the top. :-)

With the Outlook account, the MIME headers aren’t included when the emails are transferred from your computer by ActiveSync, so when you get the PR_CE_MIME_TEXT contents, it’s just the body.

With the SMS Text Messages account, the whole message is in the PR_SUBJECT property, so you don’t have to bother with the whole streams bit at all!

And there we go… few nice extra options to help get through your email a bit quicker. The code probably needs a bit more work and there might be a small memory leak or two hiding in there, but it seems to more-or-less do the trick for now. :-)

17 Responses to “Process your emails – an Outlook plugin”

  1. johnwin says:

    Great little app – I don’t know why microsoft did not put this function in from the start.

    Many 3rd party apps add this but at an overhead of a 1mb+ ‘super-app’.

    Thanks for sharing.

  2. Pierre says:

    This approach is very similar to the GTD one, isn’t it. First thing I do is to empty my inbox, move all emails in folders such as @Action (I need to do something about it), @References (Keeping for reference), @WaitingFor(if I reply/send an email and wait for someone to respond), and I have several other folders representing all my projects where I move emails to their corresponding folders for reference.

    GTD add an extra rules: if the action required about a specific email take less than 2 minutes, do it right now…

  3. Jim Vetter says:

    Hi Dale,

    Your app is exactly what I’ve been looking for.

    I’ve installed it on my Samsung Blackjack II smartphone but I can’t find the menus to use it. What do I do in pocket outlook to access the features?

    Thank you very much!!

  4. dale says:

    @Jim – When you say ‘smartphone’, do you mean “Windows Mobile Smartphone” as in a device without a touchscreen?

    If so, my extension adds itself to the context menu you get when you tap-and-hold on a message. Devices without touchscreens can’t tap-and-hold, and so don’t have context menus. Which means you won’t see my new items.

    If you’d like a copy of the code, I’d be happy to give it to you so that you can modify it to put the new items somewhere more useful for you. (I’m currently on paternity leave, and don’t really have the time to do this myself anytime soon – sorry).

  5. James Gray says:

    Hello Dale, I am very excited about this program. Whne I had my Treo 750 I tried FlexMail which “apparently” has this feature is you use Pocket Informant and the planets line up in a solar exclipse.

    I have since switched to the Motorla Q Global while I wait for the Treo 800/850.

    Anyway do you have any plans of updating this for the Windows Mobile Standard. I would try but I have no experience with this type of programming. The last time I coded it was 15 years ago in Turbo Pascal.

    how hard would it be? And would you accept donations of sorts for it as I know your tie is valuable.

    Thank you again.

  6. dale says:

    @James Gray

    Sorry – I don’t really have any plans to work on a smartphone/standard version. (because I don’t have a smartphone device).

    As for how hard it would be, probably not too hard. Presumably it’s just a matter of registering with a different menu extension point. As I said above though, it’s not something that I’d have time for at the moment. (sorry!)

  7. DanB says:

    I feel that my computer and mobile phone should be able to communicate constantly, no matter where in the world they each are.

    Since both are already in sync with exchange, this seems like like a good path to allow them to talk to each other. I think it is awesome that I can update a contact in outlook and by the time i find the contact on my phone the update has already taken place. I would like to extend this to other things.

    I am attempting to establish a communication channel. My first thought is to create a separate folder for the communication. Ie, the computer will place something in the folder, activesync will download it, and the PDA will process it. I will probably have two folders, one for communication in each direction.

    This led me to this page. I need to process the email in this folder as they are synced. Basically I would like to intercept the email so that I can process it. Any ideas?

  8. Ben says:

    Hi Dale,

    I have just stumbled on this plugin via Modaco and it works on my WM6.1 Professional device however it doesn’t play nicely with HTML emails as it copies the entire HTML code into the task or appointment.

    Is this something that can be overcome? As I would find this plugin extremely useful.

    Thanks

  9. dale says:

    @Ben – erm…. possibly?

    Hopefully, there is an alternative to PR_CE_MIME_TEXT which gets just the plain text version of the email.

    If not, I guess I could write something that strips out tags myself.

  10. Ben says:

    Thanks for the prompt feedback, I appreciate you looking into it for me. Let me know if you need any help testing. I assume you don’t use HTML emails as you would have come across this yourself.

    BTW I’ve looked round your site and found some more useful applications, I’m surprised that I haven’t come across it before.

  11. Ben says:

    Oh and while your digging in the code ;) is it possible to add to the context menu when you are viewing a message as opposed to just in the message list? Thanks

  12. [...] E-mail :: personal, work, SYA… a way to triage my various inboxes [...]

  13. Tim says:

    Great little app that I have been looking for, for a long time!
    If you do get a chance, it would be great if you could call the plugin from the body of an open message as requested previously.
    thks

  14. [...] couple of years ago, I wrote a small plugin for Outlook Mobile (the version of Outlook that you get on Windows Mobile [...]

  15. John Kurian says:

    Thank You very much. I had recently bought an HTC HD2 and was searching all over the place to move the mails to tasks (My company do not use an exchange server). I am indebted to you for providing this, as without this extension, my whole purchase of HD2 would’nt have served the purpose. I had tried FlexMail, Profimail and all weird clients to achieve this. Flexmail provides this (but the client itself is unstable on receiving large number of mails, it throws a lot of weird errors). So, I had to come back to PocketOutlook and resumed my search, until I did hit this page.

    Once again Thank You very much. This works like a breeze and you’ve made my day

  16. Dear Mr. Lane

    I have been searching for GTD Plugin for my Android Outlook Email and found ‘Email Triage’. I tried it on my old WM6 Mobile Phone, it’s wonderful. But unfortunately I can’t continue using old broken WM6 device. It would be great if you can develop similar plugin for Android or WM7.5 or suggest if already available. Thank you!

    Regards,
    Narender Kumar

  17. dale says:

    Hi Narender

    Sorry, I’m not aware of anything similar for Android or Windows Phone. And I’m afraid it’s unlikely I’ll have the time to work on it myself.

    Kind regards, D