With the August 2022 stable release (2022.1.4) there is now the capability to use the color picker control to select a color in a custom step. Typical examples would include using the color picker control to select the color for a graph or report; however, in this post, I will demonstrate using the color picker control to select the color for the text of an email.
For the user interface design, I create a page with the essential email information.
Copy Recipients section collapsed
Copy Recipients section expanded
Notice that the Body section has a note that if you want this text in a different use the color selector on the Options tab.
On the Options tab, not only is there the color picker control to select the text color for the email message, but there is also the selection of the importance of the email and whether to request a read receipt for the message.
There is also an Email Setup tab, to specify the SMTP mail host and port information.
The About tab provides information about what the custom step does. It is a recommended best practice to add this to all your custom steps.
Below is a screenshot of the Program code to send the email message with the selected options from the user interface. I have highlighted where the color picker value is referenced in the code.
Here is the full Program code for the Send SMTP Email custom step:
/* Set email options */
options
emailsys=smtp
emailhost=&smtpHost
emailport=&smtpPort
;
/* if emailBody_count is empty (doesnt exist) create it and create emailBody_1 */
%global emailBody_count ;
%if &emailBody_count eq %then %do ;
%let emailBody_count=1 ;
%let emailBody_1=&emailBody ;
%end ;
/* Format input information if multiple email addresses entered */
data _null_ ;
newEmailTo=cats(transtrn(strip(compbl(translate("&emailTo"," ",",")))," ",'" "')) ;
call symput('emailTo',strip(newEmailTo)) ;
newEmailCC=cats(transtrn(strip(compbl(translate("&emailCC"," ",",")))," ",'" "')) ;
call symput('emailCC',strip(newEmailCC)) ;
newEmailBCC=cats(transtrn(strip(compbl(translate("&emailBCC"," ",",")))," ",'" "')) ;
call symput('emailBCC',strip(newEmailBCC)) ;
run ;
/* Format and send email */
filename outmail email
from="&emailFrom"
to=("&emailTo")
cc=("&emailCC")
bcc=("&emailBCC")
subject="&emailSubject"
importance="&importance" /* Low Normal High. Default is Normal */
/* If ReadReceipt option is checked */
%if &readReceipt %then %do ;
readreceipt
%end ;
ct="text/html"
;
/* Build the body of the email */
data _null_ ;
file outmail ;
put "<html><body>" ;
put "<p style='color: #&textColor'>" ;
do i = 1 to &emailBody_count ;
if symget("emailBody_" || strip(put(i,12.))) eq '' then do ;
text=cats("<br>") ;
end ;
else do ;
text=cats(symget("emailBody_" || strip(put(i,12.))),"<br>") ;
end ;
put text ;
end ;
put "</p>" ;
put "</body></html>" ;
run;
/* Clear macro */
%symdel emailBody_count ;
The easiest method for testing a custom step is to open it in stand-alone mode.
For more information, on this refer to my previous post. To open the Send SMTP Email custom step in stand-alone mode, I right-click the custom step and select Open in a tab menu option.
I enter the following information on the Email Message Information tab:
I enter the following information on the Options tab:
Note that I have selected a color for the email text using the color picker control.
I enter the following information on the Email Setup tab:
I select the Run button to execute the custom step. Below is the email I received by running the Send SMTP Email custom step.
Note the message was sent with High importance and the text color is the color specified in the options of the custom step.
The color picker control is now available for use in custom steps. For more information on the color picker control review its documentation: SAS Help Center: Color Picker Control.
The Send SMTP Email custom step I highlighted in this blog can be downloaded from here.
Thanks to my colleague, @NicolasRobert , for his programming assistance with this custom step!
Hello Mary Kathryn! That's a great custom step!
I am wondering if it is possible to adapt it to use a list of recipients' emails from an input dataset?
And maybe use a SAS program's output as a body instead of free text?
Thanks a lot!
Yes...I would think that would be possible. You could either add input nodes to the custom step for that information or build it in as part of the flow. You would need to modify the code in the custom step to parse the list of recipients and text correctly intro macros.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.