Test.ps1 — различия между версиями
Материал из Фабиус wiki
Hisava (обсуждение | вклад) м |
Hisava (обсуждение | вклад) м |
||
(не показаны 3 промежуточные версии этого же участника) | |||
Строка 1: | Строка 1: | ||
− | param ( | + | param ( |
− | $serverSmtp = "smtp.yandex.ru", | + | $Cc = "support@sftserv.ru", |
− | $port = 587, | + | $serverSmtp = "smtp.yandex.ru", |
− | $From = "raidex@yandex.ru", | + | $port = 587, |
− | $To = "raidex@yandex.ru", | + | $From = "raidex@yandex.ru", |
− | $subject = "z", | + | $To = "raidex@yandex.ru", |
− | $user = "raidex@yandex.ru", | + | $subject = "z", |
− | $pass = "", | + | $user = "raidex@yandex.ru", |
− | $logFile = "c:\Temp\toSiel.log" | + | $pass = "", |
− | ) | + | $logFile = "c:\Temp\toSiel.log" |
+ | ) | ||
− | try | + | try |
− | { | + | { |
$files = get-childitem -Path "c:\Temp\123.xls" | $files = get-childitem -Path "c:\Temp\123.xls" | ||
foreach ($file in $files) | foreach ($file in $files) | ||
Строка 19: | Строка 20: | ||
$mes.From = $from | $mes.From = $from | ||
$mes.To.Add($to) | $mes.To.Add($to) | ||
+ | $mes.Cc.Add( $Cc ) | ||
$mes.Subject = $subject | $mes.Subject = $subject | ||
$mes.IsBodyHTML = $true | $mes.IsBodyHTML = $true | ||
− | $mes.Body = "<h1>z</h1>" | + | $mes.Body = "<code><</code>h1>z</h1>" |
$mes.Attachments.Add($att) | $mes.Attachments.Add($att) | ||
$smtp = New-Object Net.Mail.SmtpClient($serverSmtp, $port) | $smtp = New-Object Net.Mail.SmtpClient($serverSmtp, $port) | ||
Строка 34: | Строка 36: | ||
} | } | ||
− | catch [Exception] | + | catch [Exception] |
− | { | + | { |
Write-Host "Error: $($_.Exception.Message)" | Write-Host "Error: $($_.Exception.Message)" | ||
$CurrentDate = Get-Date -Format o | $CurrentDate = Get-Date -Format o | ||
"Error: $($_.Exception.Message) $CurrentDate" | Add-Content $logFile | "Error: $($_.Exception.Message) $CurrentDate" | Add-Content $logFile | ||
exit 1 | exit 1 | ||
− | } | + | } |
= Смотрите также = | = Смотрите также = | ||
[[PowerShell]] | [[PowerShell]] |
Текущая версия на 08:06, 3 июня 2021
param ( $Cc = "support@sftserv.ru", $serverSmtp = "smtp.yandex.ru", $port = 587, $From = "raidex@yandex.ru", $To = "raidex@yandex.ru", $subject = "z", $user = "raidex@yandex.ru", $pass = "", $logFile = "c:\Temp\toSiel.log" )
try
{
$files = get-childitem -Path "c:\Temp\123.xls"
foreach ($file in $files)
{
$att = New-object Net.Mail.Attachment($file)
$mes = New-Object System.Net.Mail.MailMessage
$mes.From = $from
$mes.To.Add($to)
$mes.Cc.Add( $Cc )
$mes.Subject = $subject
$mes.IsBodyHTML = $true
$mes.Body = "<
h1>z</h1>"
$mes.Attachments.Add($att)
$smtp = New-Object Net.Mail.SmtpClient($serverSmtp, $port)
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($user, $pass)
$smtp.Send($mes)
$att.Dispose()
$CurrentDate = Get-Date -Format o
"$file $CurrentDate" | Add-Content $logFile
Remove-Item $file
}
}
catch [Exception]
{
Write-Host "Error: $($_.Exception.Message)"
$CurrentDate = Get-Date -Format o
"Error: $($_.Exception.Message) $CurrentDate" | Add-Content $logFile
exit 1
}