diff --git a/social/email/61-email.js b/social/email/61-email.js index 37d40471..6c5a2d45 100644 --- a/social/email/61-email.js +++ b/social/email/61-email.js @@ -72,31 +72,45 @@ module.exports = function(RED) { tls: {rejectUnauthorized: node.tls} } - if (node.authtype === "BASIC" ) { - smtpOptions.auth = { - user: node.userid, - pass: node.password - }; + var smtpTransport; + if (node.authtype === "XOAUTH2") { + node.log("Using OAuth - setup transport later.") } - else if (node.authtype === "XOAUTH2") { - var value = RED.util.getMessageProperty(msg,node.token); - if (value !== undefined) { - if (node.saslformat) { - //Make base64 string for access - compatible with outlook365 and gmail - saslxoauth2 = Buffer.from("user="+node.userid+"\x01auth=Bearer "+value+"\x01\x01").toString('base64'); - } else { - saslxoauth2 = value; - } + else { + if (node.authtype === "BASIC" ) { + smtpOptions.auth = { + user: node.userid, + pass: node.password + }; } - smtpOptions.auth = { - type: "OAuth2", - user: node.userid, - accessToken: saslxoauth2 - }; + smtpTransport = nodemailer.createTransport(smtpOptions); } - var smtpTransport = nodemailer.createTransport(smtpOptions); this.on("input", function(msg, send, done) { + + if (node.authtype === "XOAUTH2") { + if (node.token) { + var value = RED.util.getMessageProperty(msg,node.token); + if (value !== undefined) { + if (node.saslformat) { + //Make base64 string for access - compatible with outlook365 and gmail + saslxoauth2 = Buffer.from("user="+node.userid+"\x01auth=Bearer "+value+"\x01\x01").toString('base64'); + } else { + saslxoauth2 = value; + } + } + smtpOptions.auth = { + type: "OAuth2", + user: node.userid, + accessToken: saslxoauth2 + }; + smtpTransport = nodemailer.createTransport(smtpOptions); + } + else { + node.warn(RED._("email.errors.notoken")); + } + } + if (msg.hasOwnProperty("payload")) { send = send || function() { node.send.apply(node,arguments) }; if (smtpTransport) { diff --git a/social/email/README.md b/social/email/README.md index 3d6ee45b..16b2b516 100644 --- a/social/email/README.md +++ b/social/email/README.md @@ -12,7 +12,8 @@ getting an application password if you have two-factor authentication enabled. For Exchange and Outlook 365 you must use OAuth2.0. **Notes **: - Version 2.x of this node requires **Node.js v14** or newer. + Version 3.x of this node requires **Node.js v18** or newer. + Version 2.x of this node requires **Node.js v16** or newer. Version 1.91 of this node required **Node.js v14** or newer. Previous versions of this node required **Node.js v8** or newer. diff --git a/social/email/package.json b/social/email/package.json index c7d2ddd7..6390e2d3 100644 --- a/social/email/package.json +++ b/social/email/package.json @@ -1,13 +1,13 @@ { "name": "node-red-node-email", - "version": "2.2.1", + "version": "3.0.0", "description": "Node-RED nodes to send and receive simple emails.", "dependencies": { "imap": "^0.8.19", "node-pop3": "^0.9.0", - "mailparser": "^3.6.9", - "nodemailer": "^6.9.12", - "smtp-server": "^3.13.3" + "mailparser": "^3.7.1", + "nodemailer": "^6.9.13", + "smtp-server": "^3.13.4" }, "bundledDependencies": [ "imap", @@ -33,7 +33,7 @@ "mta" ], "node-red": { - "version": ">=1.0.0", + "version": ">=2.0.0", "nodes": { "email": "61-email.js" } @@ -44,6 +44,6 @@ "url": "http://nodered.org" }, "engines": { - "node": ">=14.0.0" + "node": ">=18.0.0" } }