Jump to content
Fórum Script Brasil
  • 0

Ler conteúdo de arquivos *.log e fazer o envio por email com o conteúdo no corpo.


flavio.11d
 Share

Question

Senhores(as),

 

Preciso de uma vbs que faça a leitura do conteúdo de um arquivo *.log colocando no corpo de um email, em seguida faça o envio. Não sou expert em vbs, mas consegui desenvolver duas, a primeira faz a leitura do conteúdo de um arquivo .log  mostrando em uma janela, e a segunda zipa o arquivo.log e faz o envio por e-mail. Qualquer ajuda é bem vinda.

 

VBS 1

 

{

REM – I create FSO object.

Set FSO = WScript.CreateObject("Scripting.FileSystemObject")

 

REM – I Create OTF object .

REM – It will containall lines of the C:\FileName.Txt file.

Set OTF = FSO.OpenTextFile("C:\script\lab\arquivo.log", 1, True, 0)

 

REM –I run the loop on the OTF object to read all lines of the file.

Do While OTF.AtEndOfStream = False

       REM – The OTF.ReadLine statement reads the current

       REM – line and move the cursor to the next line.

       Current_Line= OTF.ReadLine

 

       REM – Show the current line.

       MsgBox (Current_Line)

Loop

 

REM – I close the objects

Set OTF = Nothing

Set FSO = Nothing

}

 

VBS 2

 

{

Dim fso, arq

Set fso = CreateObject("Scripting.FileSystemObject")

 

For Each objFiles In fso.GetFolder("C:\script\lab\").Files

If InStr(objFiles.Name, "arquivo02.log") Then

arq = Split(objFiles.Name, ".")

fso.MoveFile "C:\script\lab\" & objFiles.Name , "C:\script\lab\TX\" & objFiles.Name

End if

next

 

caminho = "C:\script\lab\TX\"

If fso.GetFolder(caminho).Files.Count > 0 Then

Email

End If

 

Function Email()

 

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run (Chr(34) + "C:\Arquivos de programas\7-Zip\7z.exe" + Chr(34) + " a -mx9 -t7z " + Chr(34) + "C:\script\lab\TX\arquivo02.7z" + Chr(34) + " " + Chr(34) + "C:\restless\log\" + Chr(34))

 

Set objEmail = CreateObject("CDO.Message")

 

objEmail.From = "[email protected]"

 

objEmail.Subject = "Assunto"

objEmail.To = " [email protected] "

 

objEmail.Textbody = "Corpo do email 1 " & chr(13) & "Corpo do email 2"

 

objEmail.Configuration.Fields.Item _

 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objEmail.Configuration.Fields.Item _

 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _

"192.168.63.4"

objEmail.Configuration.Fields.Item _

 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objEmail.Configuration.Fields.Update

objEmail.Configuration.Fields.Update

objEmail.AddAttachment "C:\script\lab\TX\arquivo02.7z"

objEmail.Send

 

msgbox("A função foi chamada")

 

End Function

}

    

 

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...