mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-25 01:14:16 +01:00
Update send-email.ps1
This commit is contained in:
parent
10c9caab48
commit
e505a1f823
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user