ich hab die Datei jetzt mal so abgeändert, ist das so richtig, das jetzt die erste und die letzte Mail ohne Anhang kommen?
Code: Alles auswählen
# **************************************************************
# * PowserShell Script *
# **************************************************************
# * Script: *
# * PowerShell Robocopy script with e-mail notification *
# * e-mail notification with SSL support *
# **************************************************************
# * Autor: *
# * D. Stastka, 2011-12-28 *
# **************************************************************
# Variables Backup
$SourceFolder = "F:\"
$DestinationFolder = "\\SERVER-BACKUP\Server-Backup\Sicherung_F"
$Logfile = "C:\Logs\Backup.log" + (Get-Date).tostring("yyyy-MM-dd") + "_Sicherung_F" + ".log"
# Variables Email notification
$EmailFrom = "@web.de"
$EmailTo = "@googlemail.com"
$EmailBody = "Robocopy completed successfully."
$EmailSubject = "Robocopy Job"
$SMTPServer = "smtp.web.de"
$SMTPPort = "587"
$Username = "0815"
$Password = "4711"
# Mirror Folder with Robocopy
Robocopy $SourceFolder $DestinationFolder /xd "System Volume Information" $recycle.bin /xf pagefile.sys NTUSER.Dat /mir /a-:sh /fft /LOG:$Logfile /NDL /TEE
# Send E-mail message with log file attachment
$Message = New-Object Net.Mail.MailMessage($EmailFrom, $EmailTo, $EmailSubject, $EmailBody)
$Message.Attachments.Add($Attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort)
If (-not ($SMTPPort -eq "25")){
$SMTPClient.EnableSsl = $true;
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
}
$SMTPClient.Send($Message)
# Variables Email notification
$EmailFrom = "@web.de"
$EmailTo = "@googlemail.com"
$EmailBody = "Robocopy completed successfully. See attached log file for details"
$EmailSubject = "Robocopy Job"
$SMTPServer = "smtp.web.de"
$SMTPPort = "587"
$Username = "0815"
$Password = "4711"
# Mirror Folder with Robocopy
Robocopy $SourceFolder $DestinationFolder /xd "System Volume Information" $recycle.bin /xf pagefile.sys NTUSER.Dat /mir /a-:sh /fft /LOG:$Logfile /NDL /TEE
# Send E-mail message with log file attachment
$Message = New-Object Net.Mail.MailMessage($EmailFrom, $EmailTo, $EmailSubject, $EmailBody)
$Attachment = New-Object Net.Mail.Attachment($Logfile, 'text/plain')
$Message.Attachments.Add($Attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort)
If (-not ($SMTPPort -eq "25")){
$SMTPClient.EnableSsl = $true;
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
}
$SMTPClient.Send($Message)
# Variables Email notification
$EmailFrom = "@web.de"
$EmailTo = "@googlemail.com"
$EmailBody = "Robocopy completed successfully."
$EmailSubject = "Robocopy Job"
$SMTPServer = "smtp.web.de"
$SMTPPort = "587"
$Username = "0815"
$Password = "4711"
# Mirror Folder with Robocopy
Robocopy $SourceFolder $DestinationFolder /xd "System Volume Information" $recycle.bin /xf pagefile.sys NTUSER.Dat /mir /a-:sh /fft /LOG:$Logfile /NDL /TEE
# Send E-mail message with log file attachment
$Message = New-Object Net.Mail.MailMessage($EmailFrom, $EmailTo, $EmailSubject, $EmailBody)
$Message.Attachments.Add($Attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort)
If (-not ($SMTPPort -eq "25")){
$SMTPClient.EnableSsl = $true;
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
}
$SMTPClient.Send($Message)
# EOF