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,31 +72,45 @@ module.exports = function(RED) {
tls: {rejectUnauthorized: node.tls} tls: {rejectUnauthorized: node.tls}
} }
if (node.authtype === "BASIC" ) { var smtpTransport;
smtpOptions.auth = { if (node.authtype === "XOAUTH2") {
user: node.userid, node.log("Using OAuth - setup transport later.")
pass: node.password
};
} }
else if (node.authtype === "XOAUTH2") { else {
var value = RED.util.getMessageProperty(msg,node.token); if (node.authtype === "BASIC" ) {
if (value !== undefined) { smtpOptions.auth = {
if (node.saslformat) { user: node.userid,
//Make base64 string for access - compatible with outlook365 and gmail pass: node.password
saslxoauth2 = Buffer.from("user="+node.userid+"\x01auth=Bearer "+value+"\x01\x01").toString('base64'); };
} else {
saslxoauth2 = value;
}
} }
smtpOptions.auth = { smtpTransport = nodemailer.createTransport(smtpOptions);
type: "OAuth2",
user: node.userid,
accessToken: saslxoauth2
};
} }
var smtpTransport = nodemailer.createTransport(smtpOptions);
this.on("input", function(msg, send, done) { 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")) { 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"
} }
} }