SMTP setupIs it possible to setup a SMTP server to send email through SMTP relay using JSL? See some options on SAS but not sure how to setup using JSL. Thank you
Re: SMTP setupI just tried adding this to the end of the string in my example above and it worked:
-Attachments 'C:/file.txt'
The complete example would be:
Names Default To Here( 1 );
commands = {
"Send-MailMessage -From 'email@address' -To 'email@address' -Subject 'Test mail' -Body 'Message goes here' -SmtpServer smtp.server.com -Attachments 'C:/file.txt'\!n",
"exit\!n"
};
icommand = 0;
RP = Run Program(
Executable( "PowerShell.exe" ),
ReadFunction( Function( {this}, Write( this << Read ) ) ),
WriteFunction(
Function( {this},
icommand++;
If( icommand <= N Items( commands ),
this << Write( commands[icommand] );
,
this << WriteEOF;
);
)
)
);Re: SMTP setupJ’ai essayé avec la fonction « -Attachment » en suivant le modèle de ce lien :
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7.1
En indiquant le bon chemin d’accès, je ne reçois pas de mail. Je dois faire une mauvaise manipulation ou utiliser une mauvaise syntaxe.
avez-vous un exemple de script faisant appel à une pièce-jointe SVP ?
Re: SMTP setupYou can with most likely with all the different methods. For PowerShell (which I most of the time use) see the Microsoft documentation.
Re: SMTP setupBonjour,
Comment je peux faire pour rajouter une pièce-jointe dans le mail svp ?
Re: SMTP setupIf you are on windows here an option using powershell:
Names Default To Here( 1 );
commands = {
"Send-MailMessage -From 'email@address' -To 'email@address' -Subject 'Test mail' -Body 'Message goes here' -SmtpServer smtp.server.com\!n",
"exit\!n"
};
icommand = 0;
RP = Run Program(
Executable( "PowerShell.exe" ),
ReadFunction( Function( {this}, Write( this << Read ) ) ),
WriteFunction(
Function( {this},
icommand++;
If( icommand <= N Items( commands ),
this << Write( commands[icommand] );
,
this << WriteEOF;
);
)
)
);Info about the powershell utility:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7.1
Note that this requires powershell version 2:
https://docs.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-the-windows-powershell-2.0-engine?view=powershell-7.1
Re: SMTP setupUnderstood. Maybe there is some help in this earlier thread.
Re: SMTP setupThank you for the reply. When I use Mail() function the email is sent through outlook client which blocks automatic email sending for me. I'm trying to use SMTP routing to avoid using outlook client. Is there a way to configure mail() function to use SMTP routing instead of Outlook client?
Re: SMTP setupTake a look at the 'Mail()' command.
Re: SMTP setupIn my opinion this type of issues are generally easier to debug within windows commandline or powershell as those are generally issues there, not in JMP (sometimes there are though issues with quoting in JMP).
Re: SMTP setupI managed to make it work for a path without particular characters (Example: "è", "é"...)
Is there a special function for using special characters in messages and paths?

I get this error message in the registry
I added a line to modify the encoding type in PowerShell but this does not solve the problem:


I'm also trying to skip lines in the body of my email, I tried with different methods like "\n"... but it doesn't work.
Re: SMTP setupGood morning,
Is it possible using your method to modify the body of the email (in -Body)?
For example, being able to write an email with line breaks and spaces?
Example of the email:
Good morning,
Here is the information you will receive:
- info1
- info2
THANKS
Re: SMTP setupHave you tried if it works? If I remember it should but you might have to build the body according to Powershell rules (for example https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.4#here-strings ).
When I wrote functions to send email in JMP using Send-MailMessage, I did find using -BodyAsHtml easier than just -Body.
Re: SMTP setupThank you for your answers !
Can you show an example please?
I already tried something like this
Re: SMTP setupNames Default To Here( 1 );
str = "\[$body = '
Attached to this email
You will find Instructions
'
Write-Output $body
]\";
RP = Run Program(
Executable("powershell.exe"),
Options({str}),
ReadFunction("text")
);Re: SMTP setupIs it possible to add it to the script below please?
In the “orders” section?
Names Default To Here( 1 );
commands = {
"Send-MailMessage -From 'email@address' -To 'email@address' -Subject 'Test mail' -Body 'Message goes here' -SmtpServer smtp.server.com\!n",
"exit\!n"
};
icommand = 0;
RP = Run Program(
Executable( "PowerShell.exe" ),
ReadFunction( Function( {this}, Write( this << Read ) ) ),
WriteFunction(
Function( {this},
icommand++;
If( icommand <= N Items( commands ),
this << Write( commands[icommand] );
,
this << WriteEOF;
);
)
)
);Re: SMTP setupNames Default To Here( 1 );
str = "\[$body = '
Attached to this email
You will find Instructions
'
Send-MailMessage -From 'email@address' -To 'email@address' -Subject 'Test mail' -Body $body -SmtpServer smtp.server.com
]\";
RP = Run Program(
Executable("powershell.exe"),
Options({str}),
ReadFunction("text")
);Re: SMTP setupGreat, thank you for your response!
Likewise, is it possible to add special characters to the body of the email?
Re: SMTP setupSend-Mailmessage has -Encoding parameter Send-MailMessage (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn which could work. Or maybe you need those here-strings or convert to html and manage them there.
Edit:
Names Default To Here( 1 );
str = "\[$body = @'
Use a quotation mark, like ' or ", to begin a string.
!\!"#$%&'()*+,-./:;<=>?@[\]^`{|}~‒–—―‘’‚‛“”„‟…
'@
Write-Output $body
]\";
RP = Run Program(
Executable("powershell.exe"),
Options({str}),
ReadFunction("text")
);
Re: SMTP setupThank you for your reply.
When talking about special characters, I was talking in particular about the “é” or “à” accents.
Re: SMTP setupGood morning,
Is it possible to add several attachments at the same time (in the -Attachment part)?
Thank you for your answers
Re: SMTP setupIf I read microsoft documentation correctly for Send-MailMessage you can provide it with multiple paths (and I have sent multiple attachments with it using JMP)