How to Send an Email Using PowerShell

// src -

$From = ""
$To = ""
$Cc = ""
$Attachment = "C:\users\Username\Documents\SomeTextFile.txt"
$Subject = "Here's the Email Subject"
$Body = "This is what I want to say"
$SMTPServer = ""
$SMTPPort = "587"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential) -Attachments $Attachment –DeliveryNotificationOption OnSuccess


1-save to test.ps1
2-open powershell, navigate to dir contains test.ps1
3-to execute type :
4-if got "cannot be loaded because the execution of scripts is disabled on this system"
5-run :
Set-ExecutionPolicy RemoteSigned


By: |25/01/2018|categories: