Powershell email script no longer works

This script used to work, but no longer does. I have tried a number of different examples, but nothing happens. I have 3 different emails to choose from, yahoo, gmail, and hostgator. None of them work.

$From = "me@me.com"
$To = "me@gmail.com"
$Attachment = "C:\Users\Public\Documents\EmailOrderList\OrderList.txt"
$Subject = "Subject"
$Body = "Order List Attached"
#$Body = $args[0]
$SMTPServer = "mymailserver.com"
$username = "MyUserName"
$password = "Password" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
$SMTPPort = "587"
#$SMTPPort = "465" This one does not work
#Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject `
#-Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl `
#-Credential (Get-Credential)
Send-MailMessage -ErrorAction Stop -from "$From" -to "$To" -subject "$Subject" -body "$Body" -attachment "$Attachment" -SmtpServer "$SMTPserver" -Priority  "Normal" -Credential $credential -Port $SMTPPort -UseSsl

Welcome to the forum. :wave:t4:

What changed? What does it do instead? Do you get error messages?

Regardless of that you may consider using splatting to make you code easier to read.

Nothing has changed. I simply had not used it for some time, and when I try now, nothing happens.
No error messages- nothing.
The PS script is run from this bat file: Powershell.exe -windowstyle hidden -executionpolicy remotesigned -File C:\Desktop\PSSendMail.ps1
Thanks for the tip on splatting.

Nothing on YOUR side … right? :wink:

… some time?

Did you try to run it line by line? If a connection to an email server gets rejected the server sends an error response with an error code.

After playing around with it, it finally started working. I’m not sure what the cause was. Thanks for the help.