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.
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 siebelhub.com and intelligent-advisor.com 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:
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.
Most Downloaded Zips in the same Category :
- Intelligent Advisor Custom Entity Container Extension Example (jsGrid)€4.99
- Intelligent Advisor Google Maps as Custom Input Control Extension€3.99