mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
XOAUTH2 SMTP
Exposing functionality for OAuth2 through Nodemailer. Added some error reporting if credentials are missing to match the Email-In node.
This commit is contained in:
parent
6e5bf9e06b
commit
c10671e392
@ -42,6 +42,11 @@ module.exports = function(RED) {
|
|||||||
this.secure = n.secure;
|
this.secure = n.secure;
|
||||||
this.tls = true;
|
this.tls = true;
|
||||||
var flag = false;
|
var flag = false;
|
||||||
|
this.authtype = n.authtype || "BASIC";
|
||||||
|
if (this.authtype !== "BASIC") {
|
||||||
|
this.inputs = 1;
|
||||||
|
this.repeat = 0;
|
||||||
|
}
|
||||||
if (this.credentials && this.credentials.hasOwnProperty("userid")) {
|
if (this.credentials && this.credentials.hasOwnProperty("userid")) {
|
||||||
this.userid = this.credentials.userid;
|
this.userid = this.credentials.userid;
|
||||||
} else {
|
} else {
|
||||||
@ -50,12 +55,23 @@ module.exports = function(RED) {
|
|||||||
flag = true;
|
flag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.credentials && this.credentials.hasOwnProperty("password")) {
|
if(this.authtype === "BASIC" ) {
|
||||||
this.password = this.credentials.password;
|
if (this.credentials && this.credentials.hasOwnProperty("password")) {
|
||||||
|
this.password = this.credentials.password;
|
||||||
|
} else {
|
||||||
|
if (globalkeys) {
|
||||||
|
this.password = globalkeys.pass;
|
||||||
|
flag = true;
|
||||||
|
} else {
|
||||||
|
this.error(RED._("email.errors.nopassword"));
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (globalkeys) {
|
this.saslformat = n.saslformat;
|
||||||
this.password = globalkeys.pass;
|
if(n.token!=="") {
|
||||||
flag = true;
|
this.token = n.token;
|
||||||
|
} else {
|
||||||
|
this.error(RED._("email.errors.notoken"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (flag) {
|
if (flag) {
|
||||||
@ -70,12 +86,27 @@ module.exports = function(RED) {
|
|||||||
secure: node.secure,
|
secure: node.secure,
|
||||||
tls: {rejectUnauthorized: node.tls}
|
tls: {rejectUnauthorized: node.tls}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.userid && this.password) {
|
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") {
|
||||||
|
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
|
||||||
|
};
|
||||||
}
|
}
|
||||||
var smtpTransport = nodemailer.createTransport(smtpOptions);
|
var smtpTransport = nodemailer.createTransport(smtpOptions);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user