From e505a1f8236848ac1a42308c37aa58f86557aab6 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 2 Jan 2023 20:41:43 +0100 Subject: [PATCH] Update send-email.ps1 --- Scripts/send-email.ps1 | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Scripts/send-email.ps1 b/Scripts/send-email.ps1 index 61432c51..f1471598 100755 --- a/Scripts/send-email.ps1 +++ b/Scripts/send-email.ps1 @@ -3,6 +3,14 @@ Sends an email message .DESCRIPTION This PowerShell script sends an email message. +.PARAMETER From + Specifies the sender email address +.PARAMETER To + Specifies the recipient email address +.PARAMETER Subject + Specifies the subject line +.PARAMETER Body + Specifies the body message .EXAMPLE PS> ./send-email .LINK @@ -11,15 +19,17 @@ Author: Markus Fleschutz | License: CC0 #> -$smtpServer = "smtp.example.com" -$From = read-host "Enter sender email address" -$To = read-host "Enter recipient email address" -$Subject = read-host "Enter subject" -$Body = read-host "Enter message" +param([string]$From = "", [string]$To = "", [string]$Subject = "", [string]$Body = "", [string]$SMTPServer = "") try { - $msg = new-object Net.Mail.MailMessage - $smtp = new-object Net.Mail.SmtpClient($smtpServer) + if ($From -eq "") { $From = Read-Host "Enter sender email address" } + if ($To -eq "") { $To = Read-Host "Enter recipient email address" } + if ($Subject -eq "") { $Subject = Read-Host "Enter subject line" } + if ($Body -eq "") { $Body = Read-Host "Enter body message" } + if ($SMTPServer -eq "") { $SMTPServer = Read-Host "Enter SMTP server" } + + $msg = New-Object Net.Mail.MailMessage + $smtp = New-Object Net.Mail.SmtpClient($smtpServer) $msg.From = $From $msg.ReplyTo = $From $msg.To.Add($To)