Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

Note: I haven't actually had a reason to test this, but wanted to save it as I liked the code (tongue)

 Function Send-EMail {
      Param (
          [Parameter(Mandatory=$true)]  [String]$EmailTo   = "", # default
          [Parameter(Mandatory=$true)]  [String]$EmailFrom = "", #default
          [Parameter(Mandatory=$true)]  [String]$Subject,
          [Parameter(Mandatory=$true)]  [String]$Body,
          [Parameter(mandatory=$false)] [String]$Attachment,
          [Parameter(mandatory=$true)]  [String]$Password
          $SMTPServer = ""
          $SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
          if ($attachment -ne $null) {
              $SMTPattachment = New-Object System.Net.Mail.Attachment($attachment)
          $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
          $SMTPClient.EnableSsl = $true
          $SMTPClient.Credentials = New-Object System.Net.NetworkCredential($EmailFrom.Split("@")[0], $Password);
          Remove-Variable -Name SMTPMessage
          Remove-Variable -Name SMTPClient
          Remove-Variable -Name Password
          Remove-Variable -Name Body
          Remove-Variable -Name Subject

  } #End Function Send-EMail
  $subj = "Subject"
  $body = @" Body-Text  "@
  Send-EMail -Subject $subj -Body $body -Password "myPWD" -Attachment $logFile
  • No labels