Ir para conteúdo
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

Pergunta

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 = "remetende@email.com.br"

 

objEmail.Subject = "Assunto"

objEmail.To = " destino@email.com.br "

 

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 para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,8k
×
×
  • Criar Novo...