how to send an email from a command line or visual lansa

command line example windows 10

C:\Windows\System32\WindowsPowerShell\v1.0>powershell.exe C:\Users\markm\Documents\powershell\pwemail03.ps1 markmason@gmail.com ‘”Hello World”‘ RANDY

program pwemail03.ps1

write-host “There are a total of $($args.count) arguments”
for ( $i = 0; $i -lt $args.count; $i++ ) {
write-host “Argument $i is $($args[$i])”
}

$emailtoparm=$args[0]
$envname=$args[1]
write-host “If this script were really going to do something, it would do it on $emailtoparm in the $envname environment”

$EmailFrom = “markmason12@outlook.com”

$EmailTo = $emailtoparm

$Subject = “The subjects $emailtoparm”

$Body = $envname

$SMTPServer = “smtp.gmail.com”

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)

$SMTPClient.EnableSsl = $true

$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“mark”, “lansababy”);

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Start-Sleep -Seconds 8