Update email node to point to nodejs18 and latest libs

delay creation of oauth connection
This commit is contained in:
Dave Conway-Jones 2024-06-14 15:22:56 +01:00
parent ea48b6acdd
commit df75872826
No known key found for this signature in database
GPG Key ID: 1DDB0E91A28C2643
3 changed files with 42 additions and 27 deletions

View File

@ -72,13 +72,24 @@ module.exports = function(RED) {
tls: {rejectUnauthorized: node.tls} tls: {rejectUnauthorized: node.tls}
} }
var smtpTransport;
if (node.authtype === "XOAUTH2") {
node.log("Using OAuth - setup transport later.")
}
else {
if (node.authtype === "BASIC" ) { if (node.authtype === "BASIC" ) {
smtpOptions.auth = { smtpOptions.auth = {
user: node.userid, user: node.userid,
pass: node.password pass: node.password
}; };
} }
else if (node.authtype === "XOAUTH2") { 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); var value = RED.util.getMessageProperty(msg,node.token);
if (value !== undefined) { if (value !== undefined) {
if (node.saslformat) { if (node.saslformat) {
@ -93,10 +104,13 @@ module.exports = function(RED) {
user: node.userid, user: node.userid,
accessToken: saslxoauth2 accessToken: saslxoauth2
}; };
smtpTransport = nodemailer.createTransport(smtpOptions);
}
else {
node.warn(RED._("email.errors.notoken"));
}
} }
var smtpTransport = nodemailer.createTransport(smtpOptions);
this.on("input", function(msg, send, done) {
if (msg.hasOwnProperty("payload")) { if (msg.hasOwnProperty("payload")) {
send = send || function() { node.send.apply(node,arguments) }; send = send || function() { node.send.apply(node,arguments) };
if (smtpTransport) { if (smtpTransport) {

View File

@ -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. For Exchange and Outlook 365 you must use OAuth2.0.
**Notes **: **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. Version 1.91 of this node required **Node.js v14** or newer.
Previous versions of this node required **Node.js v8** or newer. Previous versions of this node required **Node.js v8** or newer.

View File

@ -1,13 +1,13 @@
{ {
"name": "node-red-node-email", "name": "node-red-node-email",
"version": "2.2.1", "version": "3.0.0",
"description": "Node-RED nodes to send and receive simple emails.", "description": "Node-RED nodes to send and receive simple emails.",
"dependencies": { "dependencies": {
"imap": "^0.8.19", "imap": "^0.8.19",
"node-pop3": "^0.9.0", "node-pop3": "^0.9.0",
"mailparser": "^3.6.9", "mailparser": "^3.7.1",
"nodemailer": "^6.9.12", "nodemailer": "^6.9.13",
"smtp-server": "^3.13.3" "smtp-server": "^3.13.4"
}, },
"bundledDependencies": [ "bundledDependencies": [
"imap", "imap",
@ -33,7 +33,7 @@
"mta" "mta"
], ],
"node-red": { "node-red": {
"version": ">=1.0.0", "version": ">=2.0.0",
"nodes": { "nodes": {
"email": "61-email.js" "email": "61-email.js"
} }
@ -44,6 +44,6 @@
"url": "http://nodered.org" "url": "http://nodered.org"
}, },
"engines": { "engines": {
"node": ">=14.0.0" "node": ">=18.0.0"
} }
} }