none
Outlook MailItem - detecting hyperlinks RRS feed

  • Question

  • I was thinking about code that would identify MailItems with hyperlinks for later processing - flagging, categorizing...etc

    I am experienced with Office VBA and have done some work with Outlook.  Based on the other Office apps, I was looking for a hyperlink object (hyperlinks collection) on the MailItem object.

    However, after traversing the object model it doesn’t seem to have one.  That kind of makes sense in retrospect since the “body” is a freeform “container”, not like a cell in Excel or a Slide in Powerpoint which do expose hyperlinks

    I was briefly excited to see a “links” property, but quickly found out that is a task item property pertaining to the contacts on a task (I think).

    So, with all of that I was probably going to resign myself to looking at the body property of the mailitem object for the “http” string.  Not ideal, since that could easily be in the body as actual text (and not a true hyperlink).  Still, better than nothing and maybe all I can do.

    Any thoughts on this would be greatly appreciated.

    thanks,

    Jeff Henke

    Friday, September 20, 2013 2:41 PM

Answers

  • If this is Outlook 2007 or later you are automatically using WordMail as your Outlook email editor. You might also be using WordMail with Outlook 2003 or earlier, but it's optional. If you are using WordMail you can get a Word.Document object from the email and use the Word Hyperlinks collection for what you want.

    The open item is shown in an Inspector. If it's active it will be ActiveInspector. You can use ActiveInspector.WordEditor and cast it to a Word.Document object and go from there.

    If you just have a reference to the mail item you can use MailItem.GetInspector.WordEditor.


    Ken Slovak MVP - Outlook

    Friday, September 20, 2013 2:49 PM
    Moderator
  • You can load the value of the MailItem.HTMLBody property into an instance of the HTMLDocument object and then use DOM to enumerate all the links.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, September 20, 2013 4:10 PM

All replies

  • If this is Outlook 2007 or later you are automatically using WordMail as your Outlook email editor. You might also be using WordMail with Outlook 2003 or earlier, but it's optional. If you are using WordMail you can get a Word.Document object from the email and use the Word Hyperlinks collection for what you want.

    The open item is shown in an Inspector. If it's active it will be ActiveInspector. You can use ActiveInspector.WordEditor and cast it to a Word.Document object and go from there.

    If you just have a reference to the mail item you can use MailItem.GetInspector.WordEditor.


    Ken Slovak MVP - Outlook

    Friday, September 20, 2013 2:49 PM
    Moderator
  • You can load the value of the MailItem.HTMLBody property into an instance of the HTMLDocument object and then use DOM to enumerate all the links.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, September 20, 2013 4:10 PM