In Outlook VBA macro to post email body to the web, Jeremy Slade posts an Outlook macro to publish emails to a web server.
The code uses the XMLHTTP Object to send POST data to a specified URL. I'm not familiar with the actual site being used, but the XMLHTTP object leads me to believe the interface is super fast.
If an email slips through the script rule, however, you'll be stuck writing code that imports the message manually. So I've taken the liberty of doing so myself.
This code will call Jeremy's PublishMsgToWeb macro on a selected or opened message, so you can process any email manually. You can either run it after selecting an email in a folder (ActiveExplorer.Selection.Item(1)) or after opening the message for display (ActiveInspector.CurrentItem).
Sub CallPublish()
Dim Msg As Outlook.MailItem
' set reference to open/selected mail item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set Msg = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set Msg = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0
If Msg Is Nothing Then GoTo ExitProc
Call PublishMsgToWeb(Msg)
ExitProc:
End Sub
Come to think of it, setting a reference to Msg like this is pretty common, so here's an encapsulated function that does it:
Function GetMessage() As Outlook.MailItem
' returns MailItem object reference to open/selected mail item
' if any error occurs, just exit
On Error GoTo ExitProc
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set GetMessage = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetMessage = ActiveInspector.CurrentItem
Case Else
End Select
ExitProc:
End Function
Usage:
Sub CallPublish() Dim msg As Outlook.MailItem Set msg = GetMessage If Msg Is Nothing Then GoTo ExitProc Call PublishMsgToWeb(Msg) ExitProc: End Sub
Follow Me