Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepowershell
$SMTPServerName  = 'smtp.office365.com'
[string]$Username = 'user@dataself.com'    # <===  Put the SMTP Username here 
[string]$Password = '__________'                 # <===  Put the SMTP password here 
   
$SMTPPasswordEncrypted = ConvertTo-SecureString $Password -as -f  
$SMTPCredentialObj = new-object System.Management.Automation.PSCredential $Username, $SMTPPasswordEncrypted 

$From = "hello2 <$SMTPServerName>"
write-host $From + " //  " + $P_User

[string[]]$EmailTo = "cwilson@dataself.com"    #, "me2@cortsoft.com"
write-Host $EmailTo
$Subject = "6 PowershellTest .. (From = $($From)"
$Body= "PowershellTest     no ::SecurityProtocol"

##############  WARNING  ###############################
#  Once "[System.Net.ServicePointManager]::SecurityProtocol" is set the configuration is persistent in a session.
#  If testing from Powershell ISE  close PowerShell ISE and re-open it.
##############################################################
[System.Net.ServicePointManager]::SecurityProtocol = 'Tls,TLS11,TLS12'
#
Send-MailMessage -From $From -To $EmailTo -Subject $Subject -Body $Body `
 -Credential $SMTPCredentialObj  -SmtpServer $SMTPServerName -Port 587 -UseSsl -BodyAsHtml

...