查找 MAPISend 语法并替换为 BLAT 语法

查找 MAPISend 语法并替换为 BLAT 语法

我的 MAPISend 代码似乎已经失效,所以现在我尝试用 BLAT 替换超过 1,500 条 MAPISend 行。有没有办法搜索我的脚本并找到 MAPISend 语法:

“$MAPISEND_DIR/mapisend”-u“$EMAILADDRESS”-p $EMAILPW -r“$PAGERADDRESS”-s“错误 - 未找到所有文件”-m“错误”

然后切换到我的新 BLAT 语法:

blat -to“$PAGERADDRESS”-s“错误 - 未找到所有文件”-body“错误”

我认为类似 ("$MAPISEND_DIR/mapisend" -u "$EMAILADDRESS" -p $EMAILPW) 的任何内容都需要替换为 (blat) 任何以 blat 开头且同一行上有 -r 的内容都需要替换to -to,然后任何以 blat 开头并且在同一行上有 -m 的内容都需要转到 -body 。

答案1

我能够在 vb.net 中创建一个 Windows 控制台应用程序来解决我的问题。希望这能为您节省一些时间。我的日志记录到数据库中,然后从数据库发送电子邮件。您还必须创建一个用于存放日志文件的文件夹。代码:

Module MAPISend
'Convert Mapisend Message to Blat mapisend syntax -u "$EMAILADDRESS" -p $EMAILPW -r "[email protected]" -s "subject" 
'-m "body " -t \\\\$SERV\\$SHARE\\data\\log\\Data.txt

'blat syntax "\\\\$SERV\\$SHARE\\data\\log\\ProcessData.log" 
'-t "[email protected]" -s "subject" -body "body" -attach "\\\\$SERV\\$SHARE\\data\\log\\Data.xlsx" -b [email protected]

Public Sub Main(ByVal sArgs() As String)
    On Error GoTo ErrHandler

    Dim i As Integer = 0

    Dim strAttachment As String = ""
    Dim strBody As String = " "
    Dim strBodyText As String = ""
    Dim strEmailAddress As String = "[email protected]"
    Dim strFileLocation As String = ""
    Dim strPassword As String = ""
    Dim strTo As String = "[email protected]"
    Dim strSubject As String = "Test"
    Dim strGUI As String = System.Guid.NewGuid.ToString()
    Dim strHostName As String

    Dim shell
    Dim fso
    Dim file
    Dim text

    strFileLocation = "c:\windows\"
    strHostName = System.Net.Dns.GetHostName()
    'Determine which parameter is being passed in then grab the data after found
    While i < sArgs.Length             'So with each argument
        Select Case sArgs(i)
            Case "-u"                  'if -u is being passed in
                strEmailAddress = Replace(sArgs(i + 1), """", "") ' get the parameter after -u
                i = i + 1
            Case "-p"
                strPassword = Replace(sArgs(i + 1), """", "")
                i = i + 1
            Case "-r"
                strTo = Replace(Replace(sArgs(i + 1), ";", ","), """", "")
                i = i + 1
            Case "-s"
                strSubject = Replace(sArgs(i + 1), """", "")
                i = i + 1
            Case "-m"
                strBody = Replace(sArgs(i + 1), """", "")
                If strBody = "" Then
                    strBody = " "
                End If
                i = i + 1
            Case "-t"
                strBodyText = Replace(sArgs(i + 1), """", "")
                i = i + 1
            Case "-f"
                strAttachment = "-attach """ & Replace(sArgs(i + 1), """", "") & """"
                i = i + 1
        End Select
        i = i + 1
    End While


    shell = CreateObject("WScript.Shell")
    If strBodyText <> "" Then
        'Call Shell script
        shell.exec("""" & strFileLocation & "blat.exe"" """ & strBodyText & """ -t """ & strTo & """ -s """ & strSubject & """ -b ""[email protected]"" " & strAttachment & " -log ""C:\apps\mapisend\" & strGUI & ".txt"" -debug")
        Console.WriteLine("""" & strFileLocation & "blat.exe"" """ & strBodyText & """ -t """ & strTo & """ -s """ & strSubject & """ -b ""[email protected]"" " & strAttachment & " -log ""C:\apps\mapisend\" & strGUI & ".txt"" -debug")
    Else
        shell.exec("""" & strFileLocation & "blat.exe"" -t """ & strTo & """ -s """ & strSubject & """ -body """ & strBody & """ -b ""[email protected]"" " & strAttachment & " -log ""C:\apps\mapisend\" & strGUI & ".txt"" -debug")
        Console.WriteLine("""" & strFileLocation & "blat.exe"" -t """ & strTo & """ -s """ & strSubject & """ -body """ & strBody & """ -b ""[email protected]"" " & strAttachment & " -log ""C:\apps\mapisend\" & strGUI & ".txt"" -debug")
    End If
    'Wait for debug file to be generated
    For i = 0 To 30
        If My.Computer.FileSystem.FileExists("C:\apps\mapisend\" & strGUI & ".txt") Then
            fso = CreateObject("Scripting.FileSystemObject")
            file = fso.OpenTextFile("C:\apps\mapisend\" & strGUI & ".txt", 1)
            text = file.ReadAll
            Console.WriteLine(text)
             'check if file is complete if not continue for i statement
            If Not LCase(text) Like "*end of session*" Then
                Threading.Thread.Sleep(1000)
                Console.WriteLine("Waiting for \\" & strHostName & "\C$\apps\mapisend\" & strGUI & ".txt to generate end of session: " & i & " of 30")
                Continue For
            End If
            'check if file is sent if not send error
            If Not LCase(text) Like "*sending*" Or LCase(text) Like "*** warning ***" Then
                LogError("\\" & strHostName & "\C$\apps\mapisend\" & strGUI & ".txt")
            End If
            file.Close()
            Exit For
        Else
            Threading.Thread.Sleep(500)
            Console.WriteLine(i)
        End If
    Next I
    'Check if file was generated/completed within the 30 seconds
    If i = 30 Then
        LogError("Disk Latency Error: The file took more then 30 seconds to generate. \\" & strHostName & "\C$\apps\mapisend\" & strGUI & ".txt")
    End If
    Exit Sub
ErrHandler:
        LogError(Err.Description)
        Console.WriteLine("Error: " & Err.Description)
    End Sub

这是日志记录:

    Public Sub LogError(strMessage As String)
        Dim Conn1 As New ADODB.Connection
        Dim RS1 As New ADODB.Recordset
        Dim Cmd1 As New ADODB.Command
        Dim SQLConnect As String
        On Error GoTo ERR1
        SQLConnect = "Provider=sqloledb;User ID=xxxxx;Password=xxxxx;" & _
                    "Data Source=SQL01; Database=DW; " & _
                    "Persist Security Info=False;"
        Conn1.ConnectionString = SQLConnect
        Conn1.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        Conn1.Mode = ADODB.ConnectModeEnum.adModeReadWrite
        Conn1.Open()
        Cmd1.ActiveConnection = Conn1
        Cmd1.CommandText = "INSERT INTO [dbo].[dimLog]" & _
        "([LogDateTime],[PackageName],[Recipients],[Message],[MessageDescription],[EmailFormat],[HasError],[EmailSent])" & _
        "Values" & _
        "(sysdatetime(),'mapisend','[email protected]','MAPISend - ERROR - (SYSTEMS) - MAPISend','File Location: c:\mapisend\' " & _
        " + CHAR(13) + CHAR(10) + 'Log Info:' + CHAR(13)+CHAR(10) + '" + strMessage + " ','HTML',1,0)"
        Cmd1.Execute()
        Conn1.Close()
        Conn1 = Nothing
        Exit Sub
ERR1:
        Console.WriteLine("Error: " & Err.Description)
    End Sub
End Module

相关内容