Outlook: how can I send the selected message to a web server using VBA?

Purpose: to have a button on the Outlook toolbar, which, when clicked, sends the current message in its entirety (possibly as a .msg file) via the message to the URL. In this process, you need to open some browser window so that the user can enter the login information for the application at the URL (if I can’t get around this somehow, thoughts?).

I created a VBA macro and put a button in it in Outlook 2007 (although I will need to work in Outlook 2003 too).

I read about the VBA FollowHyperlink method, but I can't get a small Mac IDE to recognize it (Application.FollowHyperlink and several other attempts gave errors).

(I am a .Net programmer new to VBA, so if there is an easier way in VB.NET or C #, always point me in the right direction).

Ideas?

+1
source share
1 answer

Here is a diagram, I think it should work.

  • For communication, use the object "WinHttp.WinHttpRequest.5" COM (researching FollowHyperlink() will be pointless). This object can execute any form of HTTP request that you can think of. Link to it in an Outlook VBA project for Intellisense and early binding.
  • For the username and password, create a tiny custom form with two text fields. You can even use this form to cache the username and password (call "Hide" when the form should go out of view - all form level variables will be saved so you can use them again).
  • To prepare the payload, use this method ( KB240935 ) to get the selected item, check it for type ( If TypeOf currentItem Is MailItem Then ... ), and call SaveAs() to save it as .msg in the temporary folder. Attach it to your prepared POST request, and you're good to go.
  • For the user interface, put the button in the user CommandBar (you can even create it programmatically when the application starts). Associate a button with a Public Sub in a regular VBA module. In this Sub , decide whether to Show() your user name / password or save cached credentials and perform the necessary HTTP request processing.

Good luck It should not be too complicated.

+3
source

All Articles