Currently, the Mail function in JSL allows you to send email to a list of valid email addresses, however, it does so by incrementing through the list and sending an individual email to each recipient. On a machine where the email client requires user intervention to allow an email to be sent by JMP (e.g. Outlook on Windows in a corporate environment), this means that the user must sit and await a warning message for each recipient, sometimes with a built-in delay! This is highly inefficient, and means that sending out a report to interested stakeholders requires just as much if not more time when automated using the Mail function as it would to just manually copy and paste the report into an email.
JMP Version 16.2.0 Example code (assumes reports saved in temp folder as pngs, uses dummy email addresses):
sites = {"Site-1", "Site-2"};
report_path = Convert File Path( "$TEMP" );
default_dn = "example.com";
maillist = Associative Array(
sites,
{{// Site-1
"support@example.com", "stakeholder1@example.com", "stakeholder2@example.com", "stakeholder3@example.com"},
{// Site-2
"support@example.com", "stakeholder3@example.com", "vpsales@example.com"}}
);
For( i = 1, i <= N Items( sites ), i++,
site = sites[i];
rep_title = Eval Insert( "^site^_Report" );
temp_file_path = Convert File Path( report_path || "/" || rep_title || ".png" );
winmail = New Window( Eval Insert( "Send ^site^ Email" ),
V List Box(
Lineup Box( N Col( 2 ),
Text Box( "To:" ),
H List Box(
lb_to = List Box( maillist[site], <<NLines( 4 ) ),
V List Box(
Button Box( "Add",
nw = New Window( "Add Recipient",
<<Modal,
<<Return Result,
Text Box( "Enter a valid email address:" ),
H List Box(
teb_add = Text Edit Box( "", <<Set Width( 300 ) ),
Text Box( "@" || default_dn )
),
H List Box(
<<Horizontal Alignment( "Right" ),
Button Box( "OK" ),
Button Box( "Cancel" )
)
);
If( Char( nw[N Items( nw )] ) == "Button(1)",
lb_to << Append( nw["teb_add"] || "@" || default_dn )
);
),
Button Box( "Remove",
seli = lb_to << Get Selected Indices;
If( N Items( seli ) > 0,
newl = lb_to << Get Items;
For( i = N Items( newl ), i > 0, i--,
If( Contains( seli, i ),
Remove From( newl, i )
)
);
lb_to << Set Items( newl );
);
)
)
),
Text Box( "Subject:" ),
teb_subj = Text Edit Box( rep_title ),
Text Box( "Body:" ),
teb_body = Text Edit Box(
Eval Insert( "Hello All,\!N\!tPlease find ^rep_title^ attached.\!N\!N" ),
<<SetNLines( 8 )
),
Text Box( "Attached:" ),
Text Box( tempfilepath, <<Set Wrap( 500 ) ),
),
H List Box(
<<Horizontal Alignment( "Right" ),
Button Box( "Send",
Write( "Sending..." );
// Send Mail
to_list = lb_to << Get Items;
subjstr = teb_subj << Get Text;
bodystr = teb_body << Get Text;
Eval( Eval Expr( Mail( Expr( to_list ), subjstr, bodystr, tempfilepath ) ) );
winmail << Close Window;
),
Button Box( "Cancel",
Write( "Cancelled.\!N" );
winmail << Close Window;
)
)
)
);
);
... View more