PowerShell: Sõnumite saatmine: Difference between revisions
Created page with ' <Source lang="powershell"> <# .SYNOPSIS Sckipt teeb sonumi saatmist. Meil on html'i muster ja seal on pilt sees. See leht peab ilusti tulema saaja katte. Muster…' |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
<Source lang="powershell"> | |||
<# | |||
.SYNOPSIS | .SYNOPSIS | ||
Sckipt teeb sonumi saatmist. Meil on html'i muster ja seal on pilt sees. | Sckipt teeb sonumi saatmist. Meil on html'i muster ja seal on pilt sees. | ||
Line 13: | Line 13: | ||
.LINK | .LINK | ||
https://wiki.itcollege.ee/index.php?title=PowerShell:_Sõnumite_saatmine | https://wiki.itcollege.ee/index.php?title=PowerShell:_Sõnumite_saatmine | ||
#> | |||
function Send-Message { | #Loome funktsiooni Send-Message | ||
function Send-Message { | |||
param([string]$ToAddress=(Throw ‘$ToAddress is required!’)) | param([string]$ToAddress=(Throw ‘$ToAddress is required!’)) | ||
# server-saatja | # server-saatja | ||
Line 41: | Line 42: | ||
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer | $SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer | ||
$SMTPClient.Send($SMTPMessage) | $SMTPClient.Send($SMTPMessage) | ||
} | } | ||
#antud gruppide loetelu, kellele on vaja teha saatmine | #antud gruppide loetelu, kellele on vaja teha saatmine | ||
Send-Message "< group1@example.com >;< group2@example.com >;< group3@example.com >" | Send-Message "< group1@example.com >;< group2@example.com >;< group3@example.com >" |
Latest revision as of 13:25, 28 May 2012
<Source lang="powershell"> <#
.SYNOPSIS Sckipt teeb sonumi saatmist. Meil on html'i muster ja seal on pilt sees. See leht peab ilusti tulema saaja katte. Muster tavapäraselt on nimetatud template.html ja pilt tema sees alert.png .EXAMPLE C:\PS>.\Mail-Message.ps1 .NOTES Autor: Igor Pavlov Versioon: 0.1 Muutmise kuup2ev: 28.05.2012 .LINK https://wiki.itcollege.ee/index.php?title=PowerShell:_Sõnumite_saatmine
- >
#Loome funktsiooni Send-Message function Send-Message {
param([string]$ToAddress=(Throw ‘$ToAddress is required!’)) # server-saatja $SendingServer = "192.168.0.1" $addresses = $ToAddress if($ToAddress -isnot [Object[]]) { $addresses = ([string]$ToAddress).Split(";") } $SMTPMessage = New-Object System.Net.Mail.MailMessage # täpsustatakse tee meie HTML'ile $SMTPMessage.Body = Get-Content "X:\FULL\Path\TO\template.html" $SMTPMessage.IsBodyHtml = $true # saatja nimi $SMTPMessage.From = "service.desk@example.com" # sonumi teema $SMTPMessage.Subject = "Sonumi teema..."
foreach($singleAddress in $addresses) { $SMTPMessage.BCC.Add($singleAddress) $SMTPMessage.TO.Add($singleAddress) } # attachment $Attachment = New-Object System.Net.Mail.Attachment "X:\FULL\Path\TO\alert.png" $SMTPMessage.Attachments.Add($Attachment)
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer $SMTPClient.Send($SMTPMessage)
}
#antud gruppide loetelu, kellele on vaja teha saatmine
Send-Message "< group1@example.com >;< group2@example.com >;< group3@example.com >"