PowerShell: Sõnumite saatmine

From ICO wiki
Jump to navigationJump to search

<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
  1. >
 #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 >"