Re: SMTPsee https://community.jmp.com/t5/Discussions/Bug-or-Feature/m-p/673679#M86115 .
When it works, you have a script window open the entire time. When it fails, no window is open, and JMP is using a temporary eval context which goes away at the end of the script.
You could probably also work around the issue with a loop at the end of the script that waits for the runprogram to finish before allowing the script to finish. That won't work if you expect to run other JSL or platforms while runprogram works in the background, but approximately like this:
RP=runprogram(...);
while(1,
// check the message names, there might be another one you need too
if(RP<<CANREAD></CANREAD>
That way the eval context will persist until runprogram is done.
RunProgram context closed - SMTPHello everyone,
From an SMTP server I'm trying to send attachments to different people.
The script works correctly.
The only problem is that when I add "!//" at the beginning of my script so that it executes directly, I get the following error:

Here is the script I use:
//!
Names Default To Here( 1 );
// modifier le type de codage dans le PowerShell (windows)
stringCommand = "$OutputEncoding = [System.Text.Encoding]::UTF8";
// paramètres du mail à envoyer
commands = {
"Send-MailMessage -From '... -To '...' -Subject 'test' -Body 'test' -SmtpServer... -Attachment 'test...'",
"exit\!n"
};
// script exécution PowerShell
icommand = 0;
RP = Run Program(
Executable( "PowerShell.exe", stringCommand, ShowWindow("Hide") ),
ReadFunction( Function( {this}, Write( this << Read ) ) ),
WriteFunction(
Function( {this},
icommand++;
If( icommand <= N Items( commands ),
this << Write( commands[icommand] );
,
this << WriteEOF;
);
)
)
);
Thank you for your help !
Automation and Scripting