Friday, May 28, 2021

IBM Cloud: Send out alert emails using SMTP

Last year, I blogged about how to use Slack or email notifications for security IBM Cloud security issues. Now I added another code sample, showing how to send out notification emails using any SMTP server. The code is written in Python and Node.js and deployed as IBM Cloud Functions-based webhook. The core part in charge of connecting to an SMTP email server and sending the email is isolated as dedicated action. Thus, it is possible to use it on its own, e.g., to send out emails unrelated to the IBM Cloud Security & Compliance Center.

Cloud Functions Action and Sequence

IBM Cloud Functions are based on OpenWhisk. You can create individual actions and chain them into a sequence. This allows to better structure and reuse code. For the purpose of sending out alerts, a sequence of actions is deployed. The first action receives the alert payload and decrypts it. The payload is encrypted because it may contain sensitive information.

Send email via SMTP

The decrypted alert information is passed on to the next action in the sequence. The newly added sample (re)uses a Python function to compose the email body from the alert information and to set up a configuration object for the next action. Finally, a new action written in Node.js utilizing the Nodemailer module sends out the email via SMTP server.

You can deploy the new IBM Cloud Functions sequence using a manifest file, thereafter create a test alert to see whether it works end-to-end.

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.