Ysuran 0 Geschrieben 24. Juli 2018 Melden Geschrieben 24. Juli 2018 (bearbeitet) Hallo zusammen, ich habe folgendes Script: #Definitions $date = Get-Date -format "dd.MM.yyyy" $time = Get-Date -format "HH:mm" $timestamp = Get-Date -format "dd.MM.yyyy-HHmmss" ################################################################################## # SETTINGS ################################################################################## #$SmtpServer = The SMTP-server who's responsible for sending the mail #$smtpFrom = The displayed sender of the mail #$smtpTo = The recipient of the message #$messagesubject = The subject of the message #$FilePathName = Path and name of the exportfile #$DeleteExportOnServer = Keep exportfile after sending on the server (1 = Keep exportfile/everything else = delete exportfile ################################################################################## $SmtpServer = 'XX.X.X.XX' $smtpFrom = 'xxxxx@xxxxxxxxxx' $smtpTo = 'xxxxxxxx@xxxxxxxxx' $messagesubject = 'Datenbankstand vom ' + $date + ' um ' + $time + ' Uhr' $FilePathName = "C:\Temp\export\export-" + $timestamp + '.csv' $DeleteExportOnServer = "0" ################################################################################## Set-ADServerSettings -ViewEntireForest $true $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto $message.Subject = $messageSubject $message.IsBodyHTML = $true $result = Get-Mailbox -ResultSize unlimited |Select-Object DisplayName,PrimarySmtpAddress,DistinguishedName,Database,ExchangeGuid if (Test-Path $FilePathName) {Remove-Item $FilePathName} Get-Mailbox -ResultSize unlimited |Select-Object DisplayName,PrimarySmtpAddress,DistinguishedName,Database,ExchangeGuid |Export-Csv -Path $FilePathName $attachment = new-object Net.Mail.Attachment($FilePathName) ################################################################################## # HTMLMessage ################################################################################## $MailBody = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' $MailBody += '<html xmlns="http://www.w3.org/1999/xhtml">' $MailBody += '<head>' $MailBody += '<meta http-equiv="content-type" content="text/html:harset=iso-8859-1">' $MailBody += '<title></title>' $MailBody += '</head>' $MailBody += '<body>' $MailBody += '<b>Datenbankstand vom ' + $date + ' um ' + $time + ' Uhr:</b>' $MailBody += '<table border="1">' $MailBody += ' <tr>' $MailBody += ' <th>DisplayName</th>' $MailBody += ' <th>PrimarySmtpAddress</th>' $MailBody += ' <th>DistinguishedName</th>' $MailBody += ' <th>Database</th>' $MailBody += ' <th>ExchangeGuid</th>' $MailBody += ' </tr>' foreach ($i in $result) { $MailBody += ' <tr>' $MailBody += ' <td>' + $i.DisplayName + '</td>' $MailBody += ' <td>' + $i.PrimarySmtpAddress + '</td>' $MailBody += ' <td>' + $i.DistinguishedName + '</td>' $MailBody += ' <td>' + $i.Database + '</td>' $MailBody += ' <td>' + $i.ExchangeGuid + '</td>' $MailBody += ' </tr>' } $MailBody += '</table>' $MailBody += '</body>' $message.Body = $MailBody ################################################################################## $message.Attachments.Add($attachment) $smtp = New-Object Net.Mail.SmtpClient($smtpServer) $smtp.Send($message) $message.Dispose() $attachment.Dispose() if ((Test-Path ($FilePathName)) -and !($DeleteExportOnServer -eq "1")) {Remove-Item $FilePathName} Leider kommt diese Fehlermeldung: Exception calling "Send" with "1" argument(s): "The operation has timed out." At C:\Scripts\Mailbox-Database-Mail\MailboxDatabase.ps1:74 char:1 + $smtp.Send($message) + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SmtpException Weiß jemand was der Fehler ist? $smtp.Send($message) angelich... bearbeitet 24. Juli 2018 von Ysuran
mwiederkehr 395 Geschrieben 24. Juli 2018 Melden Geschrieben 24. Juli 2018 "The operation has timed out" heisst wahrscheinlich "Mailserver hat nicht reagiert". Stimmt der Server und der Port? Funktioniert der Zugriff mit Telnet? Wie lange dauert es, bis "220 server xy ready" kommt?
testperson 1.857 Geschrieben 24. Juli 2018 Melden Geschrieben 24. Juli 2018 Hi, kannst du mit einem der Beispiele (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-5.1) eine kurze Testmail senden? Gruß Jan
Ysuran 0 Geschrieben 24. Juli 2018 Autor Melden Geschrieben 24. Juli 2018 Noch zur Info, das Script funktioniert einwandfrei auf einem unserer 2010er Exchange Server. Leider nicht auf dem neuen 2016er. Prüfe dann heute telnet usw...
tesso 384 Geschrieben 24. Juli 2018 Melden Geschrieben 24. Juli 2018 Darf der neue Server über den entsprechenden Konnektor Mails versenden? Also prüfe, ob es mit telnet funktioniert.
Ysuran 0 Geschrieben 31. Juli 2018 Autor Melden Geschrieben 31. Juli 2018 Thema ist gelöst! Code wie folgt: #Definitions $date = Get-Date -format "dd.MM.yyyy" $time = Get-Date -format "HH:mm" $timestamp = Get-Date -format "dd.MM.yyyy-HHmmss" ################################################################################## # SETTINGS ################################################################################## #$SmtpServer = The SMTP-server who's responsible for sending the mail #$smtpFrom = The displayed sender of the mail #$smtpTo = The recipient of the message #$messagesubject = The subject of the message #$FilePathName = Path and name of the exportfile #$DeleteExportOnServer = Keep exportfile after sending on the server (1 = Keep exportfile/everything else = delete exportfile ##################################################################################$SmtpServer = 'localhost' $smtpFrom = 'XXX' $smtpTo = 'XXX' $messagesubject = 'Datenbankstand vom ' + $date + ' um ' + $time + ' Uhr' $FilePathName = "C:\temp\export-" + $timestamp + '.csv' $DeleteExportOnServer = "0" ################################################################################## Set-ADServerSettings -ViewEntireForest $true $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto $message.Subject = $messageSubject $message.IsBodyHTML = $true $result = Get-Mailbox -ResultSize unlimited |Select-Object DisplayName,PrimarySmtpAddress,DistinguishedName,Database,ExchangeGuid if (Test-Path $FilePathName) {Remove-Item $FilePathName} $result |Export-Csv -Path $FilePathName $attachment = new-object Net.Mail.Attachment($FilePathName) ################################################################################## # HTMLMessage ################################################################################## $MailBody = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' $MailBody += '<html xmlns="http://www.w3.org/1999/xhtml">' $MailBody += '<head>' $MailBody += '<meta http-equiv="content-type" content="text/html:harset=iso-8859-1">' $MailBody += '<title></title>' $MailBody += '</head>' $MailBody += '<body>' $MailBody += '<b>Datenbankstand vom ' + $date + ' um ' + $time + ' Uhr:</b>' $MailBody += '<table border="1">' $MailBody += ' <tr>' $MailBody += ' <th>DisplayName</th>' $MailBody += ' <th>PrimarySmtpAddress</th>' $MailBody += ' <th>DistinguishedName</th>' $MailBody += ' <th>Database</th>' $MailBody += ' <th>ExchangeGuid</th>' $MailBody += ' </tr>' foreach ($i in $result) { $MailBody += ' <tr>' $MailBody += ' <td>' + $i.DisplayName + '</td>' $MailBody += ' <td>' + $i.PrimarySmtpAddress + '</td>' $MailBody += ' <td>' + $i.DistinguishedName + '</td>' $MailBody += ' <td>' + $i.Database + '</td>' $MailBody += ' <td>' + $i.ExchangeGuid + '</td>' $MailBody += ' </tr>' } $MailBody += '</table>' $MailBody += '</body>' $message.Body = $MailBody ################################################################################## $message.Attachments.Add($attachment) $smtp = New-Object Net.Mail.SmtpClient($smtpServer)$smtp.UseDefaultCredentials = $true $smtp.Send($message) $message.Dispose() $attachment.Dispose() if ((Test-Path ($FilePathName)) -and !($DeleteExportOnServer -eq "1")) {Remove-Item $FilePathName}
Empfohlene Beiträge
Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren
Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können
Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!
Neues Benutzerkonto erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde dich hier an.
Jetzt anmelden