SAS Intelligent Decisioning on Viya creates decision flows to automate decisioning at scale. Decision flows can consist of rules, branches, models, Python code files, DS2 code files, and more. These decision flows offer strong customization and can mimic current business processes well. SAS Intelligent Decisioning supports a variety of activities such as fraud prevention, credit servicing, collections, personalized next-best-actions, and much more. To learn more about getting started with SAS Intelligent Decisioning, please see this blog post or this video.
Credit Decisioning Flow
Given the flexibility SAS Intelligent Decisioning offers, its available capabilities can be easily augmented through the available DS2 or Python code files nodes. An easy capability to add is the ability to send emails. These emails can alert staff of customers to follow-up with or of suspicious activity for investigation. These emails can also inform customers of new and interesting offers. Today we will go over how to add emailing to your decisioning flow using Python code files.
Before we can send emails, we need access to a SMTP server. If you don’t have a specific SMTP server in mind, you can configure the Mail Service on SAS Viya. The Mail Service can send an email to a configured SMTP server using REST API. Those with administration access can configure the connection to the Mail Service using the deployment guide instructions, such as these instructions for Linux deployments.
Once our Email Service is configured, we are ready to start sending emails. Within our Intelligent Decisioning pipeline, we will use the Python code file node with the SMTPLIB and SSL open source packages. With these packages, we will connect to our SMTP server and send the emails. More information about using these packages to send emails can be found here.
Emailing Decision Flow
When using the Python code file, your Python code must be inside a defined execute function. To read more about using Python Code Files, please see this blog.
My code block is below. First, it takes inputs variables specifying the sending email and receiving email. These variables will need to exist inside the Intelligent Decisioning flow and be marked as inputs for this node. My output parameters are empty and return value is None because my function won’t return anything.
Next, I connect to the mail server. If you are using the SAS Mail Service, this information is available in the previously configured service definition. I then create a formatted email including a subject and message. I also like to remove any extra spaces from my inputs using the strip() method to help ensure my emails are valid. Finally, you create the context, connect to the server and send the email!
''' List all output parameters as comma-separated values in the "Output:" docString. Do not specify "None" if there is no output parameter. '''
def execute (To_Email, From_Email):
'Output: '
import smtplib, ssl
# SAS Mail Server
smtp_server = "your-configured-smtp-server"
port = the-port-#-for-the-smtp-server
# Email Information
subject = "This is an email"
text = "We are sending you an email. ”
message = 'Subject: {}\n\n{}'.format(subject, text)
To_Email = To_Email.strip()
From_Email = From_Email.strip()
# Create a secure SSL context
context = ssl.create_default_context()
# Try to log in to server and send email
server = smtplib.SMTP(smtp_server, port)
server.sendmail(From_Email, To_Email, message)
server.quit()
return None
Following our theme of customization, you can modify the email subject and body as necessary to fit your needs. You can even pull in additional variables from the decision flow to add to the message. In example, if you want to alert a customer of their pending balance, add that variable to the execute function inputs and use it to build out a message, like so:
text = "Your pending balance is $" + str(pending_balance) "."
You can also send tailored emails based on the value of a variable by branching on that value. The example below is based on a preferred contact method.
Contacting Customers Decision Flow
Its simple to add emailing into your Intelligent Decisioning flow, but the customization possibilities to fit your business processes are endless!
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.