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.





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.





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)



REM – I close the objects

Set OTF = Nothing

Set FSO = Nothing






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



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

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


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") = _


objEmail.Configuration.Fields.Item _

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



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



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.

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.


  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...