Created
May 27, 2024 13:11
-
-
Save adbertram/1fc1f5d409daf337b401e2d77208201b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Long command with many parameters all on one line | |
Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject "Test Email" -Body "This is a test email." -SmtpServer "smtp.example.com" -Port 587 -UseSsl -Credential (Get-Credential) -Attachments "C:\path\to\file.txt" -Priority High -DeliveryNotificationOption OnSuccess, OnFailure | |
# Equivalent command using splatting for readability | |
$mailParams = @{ | |
From = "[email protected]" | |
To = "[email protected]" | |
Subject = "Test Email" | |
Body = "This is a test email." | |
SmtpServer = "smtp.example.com" | |
Port = 587 | |
UseSsl = $true | |
Credential = (Get-Credential) | |
Attachments = "C:\path\to\file.txt" | |
Priority = "High" | |
DeliveryNotificationOption = "OnSuccess, OnFailure" | |
} | |
Send-MailMessage @mailParams |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment