tags:

views:

481

answers:

1

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  A: 

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.

Tomalak
You can use the same idea a Tomalak answers using VSTO and C# and object such as Webclient etc you may have to be careful of the 2007, 2003 outlook references if you want it to working in both.
76mel
Though VBA might be the more portable solution, even if (or exactly because) it is less modern. I would also say it is easier to implement.
Tomalak
Thanks Tomalak, I'll give it a shot. By the way, why would investigating FollowHyperlink be pointless?
MGOwen
Update: I am trying to implement this, I plan to accept the answer and post more details here for posterity if successful.
MGOwen
I'm curious what you come up with. :-)
Tomalak