Powershell script not sending email when run in Task Scheduler

Johan Niordson 1 Reputation point
2022-07-07T22:35:40.013+00:00

I try to send mail with Send-MailMessage cmdlet in PowerShell_ISE and it works perfectly,
but when i run same PS script in a scheduled task with PowerShell I get error with the following
text:

Transaction failed. Server responded: 5.7.1 (Unknown [x.x.x.x] ) : Client host rejected : Access denied

In ISE environment - sending mail works perfectly......

Windows for business | Windows Server | User experience | PowerShell
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 48,026 Reputation points
    2022-07-08T01:58:57.597+00:00

    Are you running the ISE and the scheduled task on the same machine?

    Are you the admin of the mail server you're using as the SMTP server? Are there restrictions in place to allow only certain IP addresses to use the SMTP server? Is the IP address "x.x.x.x" in the SMTP server's "5.7.1" status response one of the allowed (or perhaps the restricted) list of addresses?


  2. Limitless Technology 40,076 Reputation points
    2022-07-11T09:56:50.53+00:00

    Hello

    Thank you for your question and reaching out. I can understand you are having issues related to Email sending.

    Please verify Task Scheduler run as account has proper permission to run the script and send the email.

    -----------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.