MAPISend構文を見つけてBLAT構文で置き換えます。

MAPISend構文を見つけてBLAT構文で置き換えます。

私のMAPISendコードが壊れているようで、1,500以上のMAPISend行をBLATに置き換えようとしています。私のスクリプトを検索してMAPISend構文を見つける方法はありますか?

"$MAPISEND_DIR/mapisend" -u "$EMAILADDRESS" -p $EMAILPW -r "$PAGERADDRESS" -s "エラー - すべてのファイルが見つかりません" -m "エラー"

次に、新しいBLAT構文に切り替えます。

blat -to "$PAGERADDRESS" -s "エラー - すべてのファイルが見つかりません" -body "error"

("$MAPISEND_DIR/mapisend" -u "$EMAILADDRESS" -p $EMAILPW) 同じことは (blat) に置き換えるべきだと思います。 blatで始まり、同じ行に-rがあるものは-に置き換える必要があります。その後、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

関連情報