I am running the latest version of PSU, and among other things I have set up a task to copy items to an SFTP. No problem with the copy parts.
However, when it comes to email sending, it would seem the email sending fails when I am disconnected from the server and not logged in to PSU, this results in error:
When I am logged in, this error does not happen, email sending a-OK:
During development I was using that, but my manager requested to replace it, following - as you might know: Microsoft itself does not recommend using the good old Send-MailMessage anymore - MS guidelines.
With that being said, I do not necessarily think the issue stems from the command, since Send-EmailMessage works perfectly, when I am running the job from the PSU console (failure only happens on scheduled runs, when my account is not logged in).
I’m also not seeing verbose messages. I could just be misreading the log snippet. Try putting this at the top. It looks like Mailzar should be spitting out a bunch of log messages.
This is the result of the changes of the catch {} block:
Transcript stopped, the output file is C:\ProgramData\UniversalAutomation\Repository\TASKS\Logs\Oodle-Transcript_01032025-060020-AM.txt
Email sending failed. Reason: Exception calling ".ctor" with "2" argument(s): "Unexpected ',' token at offset 26"
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
at System.Management.Automation.PSScriptCmdlet.DoEndProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
This is weird. I have to imagine some variable that is being passed in is affecting the behavior. Unless you are running under different credentials when scheduled vs manual, the execution context should be the same. That said, the variables passed into the script may be different from the different triggering mechanisms.
You might want to run Get-Variable at the beginning of your script and compare what’s different to see if anything stands out.