2
votes

Goal: To have a button in the Outlook toolbar which, when pressed, sends the current message in it's entirety (perhaps as a .msg file) via post to a URL. Some kind of browser window must be opened in the process so the user can enter login details for the application at the URL (unless I can get around this somehow, thoughts?).

I have created a VBA Macro and put a button for it in Outlook 2007 (though I'll need this to work in Outlook 2003 too, at least).

I've read about the VBA FollowHyperlink method, but I can't get the little VBA Macro IDE to recognise it (Application.FollowHyperlink and several other attempts gave errors).

(I'm a .Net programmer new to VBA, so if there is a simpler way in VB.NET or C# by all means point me in the right direction).

Ideas?

1

1 Answers

4
votes

Here is an outline of how I think it should work.

  • For the communication, use the a "WinHttp.WinHttpRequest.5" COM object (investigating FollowHyperlink() will be pointless). This object can do any form of HTTP request you can think of. Reference it in the Outlook VBA project to get Intellisense and early binding.
  • For username and password, create a tiny custom form with two text boxes. You can even use that form to cache username and password (call "Hide" when the form should go out of view - all form level variables will be retained so you can use them again).
  • For preparing the payload, use this method (KB240935) to get the currently selected item, check it for type (If TypeOf currentItem Is MailItem Then ...), and call SaveAs() to save it as .msg in a temporary folder. Attach it to your prepared POST request, and you are good to go.
  • For the user interface, put a button in a custom CommandBar (you can even create one programmatically at Application start). Link the button to a Public Sub in an ordinary VBA module. In this Sub, decide if you need to Show() your custom username/password dialog, or if cached credentials exist, and do the necessary HTTP request handling.

Good luck! It should not be too complicated.