Jump to content

Mailversand per PowerShell-Script - The operation has timed out


Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte erstelle einen neuen Beitrag zu Deiner Anfrage!

Empfohlene Beiträge

Geschrieben (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 von Ysuran
Geschrieben

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}

Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte erstelle einen neuen Beitrag zu Deiner Anfrage!

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 erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...