r/PowerShell • u/YourDadSolanki01 • Feb 25 '26
Infra health check script not sending mail
We are running our health checks with scripts. This script will generate html report and send mail attaching the html as attachment and also content in mail body to our group id but from last 2 days it is not sending mail . HTML file is getting generated successfully. We append html file on every run. Tested smtp with powershell smtp command it works fine by giving credentials but mail sending not working through this health check script. We have added TLS1.2 thinking it might be the issue. But same result. There is no change at SMTP end( same script working fine 2 days back). It was running under scheduled task, we tried to run it directly from Powershell thinking any issue with task or account.
Any idea what to check in this?
4
u/sn0rg Feb 25 '26
Is your IP allowed to relay from the SMTP server?
3
u/evasive_btch Feb 25 '26 edited Feb 25 '26
Try Send-MailMessage in a terminal, doing the same thing that the script does. Does it return an error?
If not, check mail server logs. Did the server receive the send-email request? If so, did it send the request?
If it did, check anything between mail-server and recipient client.
10
u/Pure_Fox9415 Feb 25 '26
Why guess? Just add logging to the script and check your smtp server logs. Also, it's better not to produce email garbage with attachments, point its html output to webserver folder and send email with a link, not attachment. Or even better, just tell people, where to find this report (by url).
5
u/[deleted] Feb 25 '26
Powershell logs say what?
AV logs say what?
I had to route around isp blocks a couple times when I did this.
3
u/420nukeIt Feb 25 '26
There’s like 100 things that it could be try posting the script to begin with? Are we troubleshooting or here for emotional support lol
1
u/wdomon Feb 25 '26
Cut the problem in half by checking whether the SMTP relay's logs are showing the message. If SMTP logs don't show the attempt to send it, then the issue is likely with the script itself. If SMTP logs do show the attempt but it's still not being delivered, stop looking at the script and look at SMTP/delivery (SPF, DKIM, etc).