Node-red-node-email - allow msg.userid & msg.password

I have a Page (on a secured server with secure user login) and needed for the admin to be able to submit the userid and password via a msg and not with the built in credentials. Also Enable/Disable the TLS and Use secure connection options via msg.tls (boolean) and msg.secureconnection (boolean). Also added msg.port as well

Ive updated and tested the node is working for me with these changes but wonder if it has any use as a PR or should I just create a contrib off shoot? Working on the documentation now. Let me know if you want it as a PR.

this.on("input", function(msg, send, done) {
            if (msg.hasOwnProperty("payload")) {
                send = send || function() { node.send.apply(node,arguments) };
                if (msg.userid || msg.password || msg.tls === true || msg.tls === false || msg.secureconnection === true || msg.secureconnection === false || msg.port) {
                    if (msg.userid && msg.password) { //User specified userid & password via message
                        smtpOptions.auth = {
                          user: msg.userid,
                          pass: msg.password
                    if (msg.tls === true || msg.tls === false) { //User specified tls boolean via message
                        smtpOptions.tls.rejectUnauthorized = msg.tls;
                    if (msg.secureconnection === true || msg.secureconnection === false) { //User specified secureconnection boolean via message
               = msg.secureconnection;
                    if (msg.port) {
                        smtpOptions.port = parseInt(msg.port, 10); //User specified port via message
                    smtpTransport = nodemailer.createTransport(smtpOptions);

the only issue i see is it does add a little overhead because it has to createTransport for nodemailer each time vs having it stored.

The default pattern we use is that if configured then use the value in the node. Only allow msg properties if the option is blank.

1 Like

So your saying shamaybe to a PR if I code it up to only allow msg properties if the option is blank....Got ya :slight_smile: I'll get working on it.

Yes. But it’s not that simple :-). Some of those options are checkboxes so can’t be left blank.

It would look funny but I could put drop-down on those of enable, disable, msg.tls ???? I just wonder how many other users are in my boat ......... Ive never seen a request for what im doing.... might be best to bring its as close to your standards and make a contrib and keep it up to date with the official node. If and when you get people asking for what im doing then we can just do a PR then.

Hey It did make me want to fix the documentation on the official node so there is that :stuck_out_tongue:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.