Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created January 3, 2024 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/410ed0cfc3ab112e519327ace1f31244 to your computer and use it in GitHub Desktop.
Save bill-long/410ed0cfc3ab112e519327ace1f31244 to your computer and use it in GitHub Desktop.
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Server,
[Parameter(Mandatory)]
[string]
$To,
[Parameter(Mandatory)]
[string]
$From,
[Parameter()]
[string]
$Subject = "Test",
[Parameter()]
[string]
$Body = "Test",
[Parameter()]
[switch]
$DisableTLS
)
$msg = New-Object System.Net.Mail.MailMessage($From, $To)
$msg.Subject = $Subject
$msg.Body = $Body
$client = New-Object System.Net.Mail.SmtpClient($Server)
if (-not $DisableTLS) {
$client.EnableSsl = $true
}
$client.Send($msg)
# If this generates an error use the following command to see the details:
# $Error[0] | fl * -force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment