crackhawk
Goto Top

Logfileinhalt per E-Mail senden

Hallo Admins!

Folgendes Problem:
Ich möchte mir den Inhalt einer Robocopy Logdatei per E-Mail zukommen lassen.
Die Datei als Anhang mitzusenden ist kein Problem, jedoch benötige ich den Inhalt direkt in der E-Mail da diese später automatisch ausgelesen und ein Backup Task als erfolgreich oder fehlerhaft gekennzeichnet wird.

Ich habe mir mit Hilfe von blat.exe bereits folgendes *.vbs Script gebastelt:
Dim objFileSystem, objInputFile
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objInputFile = objFileSystem.OpenTextFile("logdatei.log", 1)
' read everything in an array
logfileinhalt = objInputFile.ReadAll
attribute = "-to empfaenger@provider.de -f absender@provider.de -server smtp.server.de -s Betreff"
mailinhalt = "-body """&logfileinhalt&""""
set WshShell = CreateObject("WScript.Shell")
WshShell.Run("blat.exe "&attribute&" "&mailinhalt)
objInputFile.Close

Das funktioniert auch einwandfrei, jedoch nicht mit Großen Logdateien da ich die Fehlermeldung "Der Dateiname oder die Erweiterung ist zu lang." bekomme. Irgendwie verständlich wenn ich die komplette Logdatei in die Dateierweiterung klatsche.

Was habe ich nun für Möglichkeiten mir den Inhalt der Datei per E-Mail zukommen zu lassen? Ich bin für alle Infos und alternativen offen.

Vielen Dank!

Gruß,
crackhawk

Content-Key: 220320

Url: https://administrator.de/contentid/220320

Printed on: April 25, 2024 at 05:04 o'clock

Member: SlainteMhath
SlainteMhath Oct 24, 2013 at 10:54:20 (UTC)
Goto Top
Moin,

blat hat doch einen Parameter der einen Filenamen nimmt und den Inhalt dann als Mailbody verwendet... wirf doch mal einen Blick in die Hilfe und/oder besorg dir die aktuelle Version.

lg,
Slainte
Member: Bitboy
Bitboy Oct 24, 2013 at 10:57:32 (UTC)
Goto Top
Hi,

indem du die Mail vbs only sendest statt noch externe Programme zu benutzen?

Set objMessage = CreateObject("CDO.Message")   
objMessage.Subject = "Example CDO Message"   
objMessage.From = "sender@mail"   
objMessage.To = "recievier@mail"  
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.server.fqdn"  
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
objMessage.Configuration.Fields.Update

'The line below shows how to send using HTML included directly in your script  
objMessage.HTMLBody = "<h1>This is some sample message html.</h1>"   

'The line below shows how to send a webpage from a remote site  
'objMessage.CreateMHTMLBody "http://www.paulsadowski.com/wsh/"  

'The line below shows how to send a webpage from a file on your machine  
'objMessage.CreateMHTMLBody "file://c|/temp/test.htm"  

'objMessage.Bcc = "you@your.com"  
'objMessage.Cc = "you2@your.com"  
objMessage.Send
 


Zusammenkopiert von hier: http://stackoverflow.com/questions/582756/smtp-configuration-sendusing- ... und hier http://www.paulsadowski.com/wsh/cdo.htm in weniger als 5 Minuten ;)
Member: colinardo
colinardo Oct 24, 2013 at 10:57:43 (UTC)
Goto Top
Hallo crackhawk,
machs doch direkt mit Powershell, dann brauchst du kein 'Blat':
(Mailserver,Port,Username,Passwort in Zeile 2-5 eintragen, Logfile in Zeile 20 angeben und noch die Mailadressen in Zeile 21 ändern)
Function sendmail($FROM,$TO,$SUBJECT,$BODY,$ATTACHMENTS){
  $SMTPHOST = "smtp.mailserver.de"  
  $SMTPPORT = 25
  $SMTPUSER = "USERNAME"  
  $SMTPPass = "PASSWORD"  
  $SMTPClient = New-object System.Net.Mail.SmtpClient($SMTPHOST,$SMTPPORT)
  $SMTPClient.EnableSsl = $true
  $Mail = new-object System.Net.Mail.MailMessage
  $Mail.from = $FROM 
  $Mail.to.add($TO)
  $SMTPClient.Credentials = new-object System.Net.NetworkCredential($SMTPUSER,$SMTPPass)
  $Mail.Subject = $SUBJECT
  $Mail.Body = $BODY
  # Add Attachments
  foreach ($att in $ATTACHMENTS){
    $Mail.Attachments.Add($att.FullName)
  }
  $SMTPClient.Send($Mail)
}

$logContent = Get-Content "C:\Temp\logfile.txt" | Out-String  
sendmail "sender@email.de" "empfaenger@email.de" "TESTBETREFF" $logContent  
Grüße Uwe
Member: crackhawk
crackhawk Oct 24, 2013 at 11:23:15 (UTC)
Goto Top
Vielen Dank für die Antworten, mit dem Powershell Script funktioniert es tatsächlich. Viel einfacher jedoch fand ich dann doch die verwendung von blat.exe mit dem entsprechenden (mir bis gerade eben) unbekannten parameter -bodyF. Ich habe jetzt eine zweizeilige batch Datei angelegt mit der es einwandfrei funktioniert:
@echo off
blat.exe -to empfaenger@provider.de -f absender@provider.de -server smtp.server.de -bodyF logdatei.log -s Betreff

Vielen Dank!
crackhawk