mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-29 03:13:55 +01:00
Update send-email.ps1
This commit is contained in:
parent
10c9caab48
commit
e505a1f823
@ -3,6 +3,14 @@
|
|||||||
Sends an email message
|
Sends an email message
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script sends an email message.
|
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
|
.EXAMPLE
|
||||||
PS> ./send-email
|
PS> ./send-email
|
||||||
.LINK
|
.LINK
|
||||||
@ -11,15 +19,17 @@
|
|||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
$smtpServer = "smtp.example.com"
|
param([string]$From = "", [string]$To = "", [string]$Subject = "", [string]$Body = "", [string]$SMTPServer = "")
|
||||||
$From = read-host "Enter sender email address"
|
|
||||||
$To = read-host "Enter recipient email address"
|
|
||||||
$Subject = read-host "Enter subject"
|
|
||||||
$Body = read-host "Enter message"
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$msg = new-object Net.Mail.MailMessage
|
if ($From -eq "") { $From = Read-Host "Enter sender email address" }
|
||||||
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
|
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.From = $From
|
||||||
$msg.ReplyTo = $From
|
$msg.ReplyTo = $From
|
||||||
$msg.To.Add($To)
|
$msg.To.Add($To)
|
||||||
|
Loading…
Reference in New Issue
Block a user