Option Explicit Sub ConsUnsubProc(MyMail As MailItem) '-------------------------------------------------------------------------------- ' Procedure : ConsUnsubProc ' Author : Michael Langford (carnix) ' Date : 05/14/2010 ' Purpose : Acts as a wrapper shell so that parameters from Outlook can be passed ' to an external application or script. ' Input(s) : ' MyMail : Standard Outlook MailItem object ' Remarks : This script is designed for use in the ThisOutlookSession object and ' to be called within an Outlook Rule in the "run a script" action context. '-------------------------------------------------------------------------------- Const ExternalProcessor As String = "C:\PATH\TO\unsubproc.pl" Const lngCancelled_c As Long = 0 Dim strID As String Dim objMail As Outlook.MailItem Dim strCmd As String strID = MyMail.EntryID Set objMail = Application.Session.GetItemFromID(strID) strCmd = ExternalProcessor & " " & objMail.Subject If VBA.LenB(strCmd) = lngCancelled_c Then Exit Sub End If CommandLine strCmd, False, vbMinimizedNoFocus Set objMail = Nothing End Sub Public Function CommandLine(command As String, Optional ByVal keepAlive As _ Boolean = False, Optional windowState As VbAppWinStyle = VbAppWinStyle.vbHide) _ As Boolean '-------------------------------------------------------------------------------- ' Procedure : CommandLine ' Author : Aaron Bush (Oorang) ' Date : 10/02/2007 ' Purpose : Provides a simple interface to execute a command lines from VBA. ' Input(s) : ' command : The DOS command you wish to execute. ' keepAlive : Keeps the DOS window open *after* command has been ' executed. Default behavior is to auto-close. (See ' remarks section for additional information.) ' windowState : Determines the window state of the DOS prompt ' *during* command execution. ' Output : True if completed with no errors, False if error encountered. ' Remarks : If the windowState property is set to vbHide while the keepAlive ' parameter is set to True, then windowState will be changed to ' vbNormalFocus. '-------------------------------------------------------------------------------- On Error GoTo Err_Hnd Const lngMatch_c As Long = 0 Const strCMD_c As String = "cmd.exe" Const strComSpec_c As String = "COMSPEC" Const strTerminate_c As String = " /c " Const strKeepAlive_c As String = " /k " Dim strCmdPath As String Dim strCmdSwtch As String If keepAlive Then If windowState = vbHide Then windowState = vbNormalFocus End If strCmdSwtch = strKeepAlive_c Else strCmdSwtch = strTerminate_c End If strCmdPath = VBA.Environ$(strComSpec_c) If VBA.StrComp(VBA.Right$(strCmdPath, 7), strCMD_c, vbTextCompare) <> _ lngMatch_c Then strCmdSwtch = vbNullString End If VBA.Shell strCmdPath & strCmdSwtch & command, windowState CommandLine = True Exit Function Err_Hnd: CommandLine = False End Function