How to email all Qlik Sense Cloud users

Ctrl-Q NR and Node-RED can be used to get metadata for users in a Qlik Sense Cloud tenant. This can be combined with the email node in Node-RED to create a basic but quite flexible email service that can send emails to all users with email addresses in the tenant.

How to email all Qlik Sense Cloud users

That title does sound rather spammy... it's not that bad though.

💡
Let's say you have a Qlik Sense Cloud tenant and you want to contact all the people that have access to the tenant.

Maybe to inform them about a coming service window or invite them to a coming training session.

In some cases there may be an Active Directory group backing the Sense Cloud authentication - then you could probably use that AD group to send an email to your users.

Qlik Sense Cloud however also keeps an optional email property for all users.
That property is usually not set for service accounts and similar, but for real, human users it is usually set (but not always? I don't know - I have yet to see a real user that does not have an email address though).

So the question is:

Can we use Node-RED and Ctrl-Q NR to get user metadata from Qlik Sense Cloud, then send emails to all (0r some, of course) users?

Turns out we can.

Solution

The flow below is pretty basic. The basics are:

  1. Get an array with all user objects for the configured Sense tenant.
  2. Split the array into separate Node-RED messages, one for each user account.
  3. For each user message, check if it has an email property.
  4. If there is an email property, build an email message and send it using GMail.
Sending emails to all tenant users that have an email address.
There are four users in this tenant.
Only one user has an "email" property.
The email sent can contain HTML formatting, have any subject, cc:s etc.

Here is the flow above, ready to be imported into Node-RED:

[{"id":"c98e392c2e5c55b0","type":"comment","z":"ae8c14c4e384b6d4","name":"Send emails to all tenant users that have an email address","info":"","x":240,"y":460,"wires":[]},{"id":"172189ae6ed1b17d","type":"qscloud-user","z":"ae8c14c4e384b6d4","name":"","tenant":"a329efb577d33158","op":"r","x":400,"y":520,"wires":[["e85adf9132ea1af4","82e20f8570b1d5fa"]]},{"id":"b3365d21e6176872","type":"inject","z":"ae8c14c4e384b6d4","name":"Get all users in tenant","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":520,"wires":[["172189ae6ed1b17d"]]},{"id":"9c7cdda553071926","type":"switch","z":"ae8c14c4e384b6d4","name":"","property":"payload.email","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":true,"outputs":1,"x":260,"y":600,"wires":[["bb6ac91d9cbae06a","992cfe38a5ca786d"]]},{"id":"e85adf9132ea1af4","type":"change","z":"ae8c14c4e384b6d4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.user","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":520,"wires":[["b5ca42812086d1fd"]]},{"id":"b5ca42812086d1fd","type":"split","z":"ae8c14c4e384b6d4","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":120,"y":600,"wires":[["9c7cdda553071926"]]},{"id":"6ad0453f4044c193","type":"debug","z":"ae8c14c4e384b6d4","name":"All users with email address set","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":660,"y":600,"wires":[]},{"id":"bb6ac91d9cbae06a","type":"join","z":"ae8c14c4e384b6d4","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":420,"y":600,"wires":[["6ad0453f4044c193","164e2263c3db54cb"]]},{"id":"82e20f8570b1d5fa","type":"debug","z":"ae8c14c4e384b6d4","name":"All users","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":480,"wires":[]},{"id":"164e2263c3db54cb","type":"debug","z":"ae8c14c4e384b6d4","name":"Users with email address","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload.length","targetType":"msg","statusVal":"payload.length","statusType":"auto","x":640,"y":640,"wires":[]},{"id":"992cfe38a5ca786d","type":"change","z":"ae8c14c4e384b6d4","name":"Build properties needed for email","rules":[{"t":"set","p":"payload_orig","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"to","pt":"msg","to":"payload.email","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"Welcome to Ctrl-Q training next week","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":" <img src=\"https://github.com/ptarmiganlabs/ctrl-q-nr/blob/main/docs/logo/ctrl-q-nr_25.png?raw=true\" alt=\"Ctrl-Q NR logo\">   <h1>👋 Hello, [Name]</h1>   <p>We are excited to announce that we are offering a free Ctrl-Q NR training session for our valued users.</p>  <p>This session will help you learn how to use Ctrl-Q NR, a powerful Node-RED module that makes it easy to<br> interact with both client-managed and cloud versions of Qlik Sense from within Node-RED.</p>  <p>The training session will cover the following topics:</p>  <ul>  <li>How to install Ctrl-Q in Node-RED</li>  <li>How to use Ctrl-Q to interact with Sense apps</li>  <li>How to use Ctrl-Q to monitor app reloads in Qlik Sense Cloud</li>  <li>How to use Ctrl-Q to send emails to all users in client-managed or cloud Qlik Sense environments</li>  <li>How to get involved in Ctrl-Q development</li>  </ul>  <p>The training session will be held on <strong>Tuesday, September 19, 2023</strong> from <strong>10:00 AM to 11:00 AM (CET)</strong>.</p>  <p>Please register for the session by filling out this form: <a href=“2”>Ctrl-Q NR Training Registration</a></p>  <p>We hope you will join us for this informative and interactive session.<br> If you have any questions, please feel free to contact us at <strong>info@ptarmiganlabs.com</strong>.</p>  <p>Thank you,</p>  <p>The Ctrl-Q Team</p>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":700,"wires":[["73b26715e11f91a3"]]},{"id":"2ef2e1897b67a648","type":"e-mail","z":"ae8c14c4e384b6d4","server":"smtp.gmail.com","port":"465","authtype":"BASIC","saslformat":true,"token":"oauth2Response.access_token","secure":true,"tls":true,"name":"","dname":"Send email using GMail","x":500,"y":780,"wires":[]},{"id":"73b26715e11f91a3","type":"function","z":"ae8c14c4e384b6d4","name":"Inject recipients name in email body","func":"msg.payload = msg.payload.replace(/\\[Name\\]/, msg.payload_orig.name);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":700,"wires":[["2ef2e1897b67a648"]]},{"id":"a329efb577d33158","type":"qscloud-tenant","name":"Dummy API key authorisation","tenant":"abcdefgh123456789","region":"eu","authType":"apikey","clientId":"","clientSecret":"","apiKey":"abcdefgh123456789abcdefgh123456789abcdefgh123456789"}]