BookmarkSubscribeRSS Feed

SAS Viya: Send Email Custom Step Featuring the Color Picker Control

Started ‎10-19-2022 by
Modified ‎04-12-2023 by
Views 2,520

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.

 

UI Design

 

For the user interface design, I create a page with the essential email information.

 

1_Email-1.png

Copy Recipients section collapsed

 

2_Email-1.png

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.

 

3_Email.png

 

There is also an Email Setup tab, to specify the SMTP mail host and port information.

 

  4_Email.png

  

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.

 

5_Email.png

 

Program

 

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.

 

6_Email.png

 

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 ;

 

Test the Custom Step

 

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:

 

7_Email-1.png

 

I enter the following information on the Options tab:

 

8_Email.png

 

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:

 

9_Email.png

 

  I select the Run button to execute the custom step.  Below is the email I received by running the Send SMTP Email custom step.

 

10_Email.png

 

 

Note the message was sent with High importance and the text color is the color specified in the options of the custom step.  

 

Summary

 

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.  

Acknowledgements

Thanks to my colleague, @NicolasRobert , for his programming assistance with this custom step!  

Version history
Last update:
‎04-12-2023 10:52 AM
Updated by:
Contributors

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags