We can create a basic function to send email with PowerShell by using the following, we will call it Send-SimpleMail. function Send-SimpleMail ([st
We can create a basic function to send email with PowerShell by using the following, we will call it Send-SimpleMail.
function Send-SimpleMail ([string]$subject, [string]$body) { $From = "youremail@yourcompany.com" $To = "recipientemail@yourcompany.com" $SMTPServer = "smtp.gmail.com" $SMTPClient = New-Object Net.Mail.SmtpClient($stmpserver, 587) $SMTPClient.EnableSSL = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username" "Password"); $SMTPClient.Send($from, $to, $subject, $Body) } Send-SimpleMail -subejct "Test-Subject" -body "Testing body text."
COMMENTS