Send an Email in Intelligent Advisor

This article grew out of a discussion of an interesting use case over on the freshly revamped Forum for Intelligent Advisor. The question of how to Send an Email in Intelligent Advisor was a good one for several reasons – not just because it was an immediately clear business requirement, but also because everyone involved realized that the best way to send mail – from the server side, not from the client – was a desirable goal but not always an option for a myriad of reasons. Best practices are not always achievable. As the old saying goes, “no plan survives contact with the enemy”.

So, back to the idea – send an email in Intelligent Advisor. Let’s assume a few things. You are working on an Interview and you want to email the user something at the end of the Interview. You either cannot or do not want to go to the (heavy) process of setting up a Connection to the CX, building web services, creating workflow processes or whatever trigger-based procedure you want to have run on the server. It just costs too much or is not possible for any one of a hundred reasons.

Well there are a couple of answers available to us, and they both involve JavaScript. Ironically the easiest scenario involves creating a connection. But it is a very special connection – one that was introduced in 20D. The Interview Extension Connection Type is basically a mechanism to allow management of web service (REST) calls during an Interview, where the details of the call (including for example the Basic Authentication details that you don’t want to have in your JavaScript code) are stored on the Hub. So you request a call outbound from the Interview and it goes to the Hub, the Hub does the call and responds back to you in the browser, neatly making CORS issues a lot easier to handle as well.

To send an Email in Intelligent Advisor realistically requires a service to do the emailing for you. In this example case I chose Mailgun – because we already use them at the and offices for various mass-mailing tasks. They provide detailed logs of what got sent, bounced, redirected and so on, which is far more robust that just writing some PHP code. Plus, they provide – and this is the key – a REST api. So we can build a connection in the Hub to mailgun, complete with our API details and URL. This service does not provide a “healthcheck” url (an equivalent of CheckAlive) so we don’t need to fill that in. It will look like this:

Send an Email in Intelligent Advisor - setup Connection

So now that we have that connection to Mailgun sorted, in our code we need to leverage the connection using the new interview.fetch() method. We need to ensure that whatever we are sending (subject, body) is correctly encoded but other than that it is fairly straightforward. Obviously in a real-world scenario we would want to verify the server response message but for now we can just content ourselves with saving it as an attribute. And within a few seconds our email arrives in the inbox of the intended recipient. Thanks to Intelligent Advisor and Mailgun.

If you are interested in the Zip Archive (20D) you can download it for free from the shop. Of course, you will need a Mailgun subscription and set up your API key in Mailgun, and configure your Interview Extension Connection to point your Mailgun instance. Note that this project will not work in the Debugger, and will require you to deploy it to a 20D Hub to be able to create the Connection.

Send Email in Intelligent Advisor…with an attachment?

I can hear you already asking the next, obvious question – what about sending a PDF form in the email as well – can it be done? It can be done, with a little more effort. Stay tuned for that in a few days. We have several articles that deal with this concept, including the ever-popular TRANSCRIPT and using a Promise to retrieve data from a REST API.

Most Downloaded Zips in the same Category :

Author: Richard Napier

Richard Napier joined Siebel Systems in 1999 and took up the role of managing the nascent Siebel University in Southern Europe. He subsequently was Director of Business Development and Education for InFact Group (now part of Business & Decisions) for 8 years. He now runs Intelligent Advisor IT Consulting OÜ. Owner of, he also is Co-Founder of the Siebel Hub.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Logo by Southpaw Projects LLC