diff --git a/social/email/61-email.js b/social/email/61-email.js
index 6c5a2d45..ccb99d7f 100644
--- a/social/email/61-email.js
+++ b/social/email/61-email.js
@@ -14,7 +14,6 @@ const { domainToUnicode } = require("url");
module.exports = function(RED) {
"use strict";
- var util = require("util");
var Imap = require('imap');
var Pop3Command = require("node-pop3");
var nodemailer = require("nodemailer");
@@ -34,7 +33,7 @@ module.exports = function(RED) {
this.outserver = n.server;
this.outport = n.port;
this.secure = n.secure;
- this.tls = true;
+ this.tls = n.tls;
this.authtype = n.authtype || "BASIC";
if (this.authtype !== "BASIC") {
this.inputs = 1;
@@ -62,7 +61,6 @@ module.exports = function(RED) {
this.error(RED._("email.errors.notoken"));
}
}
- if (n.tls === false) { this.tls = false; }
var node = this;
var smtpOptions = {
@@ -87,9 +85,9 @@ module.exports = function(RED) {
}
this.on("input", function(msg, send, done) {
-
if (node.authtype === "XOAUTH2") {
if (node.token) {
+ var saslxoauth2 = "";
var value = RED.util.getMessageProperty(msg,node.token);
if (value !== undefined) {
if (node.saslformat) {
@@ -119,7 +117,7 @@ module.exports = function(RED) {
node.warn(RED._("node-red:common.errors.nooverride"));
}
var sendopts = { from: ((msg.from) ? msg.from : node.userid) }; // sender address
- sendopts.to = node.name || msg.to; // comma separated list of addressees
+ sendopts.to = node.name || msg.to; // comma separated list of addresses
if (node.name === "") {
sendopts.cc = msg.cc;
sendopts.bcc = msg.bcc;
@@ -167,9 +165,9 @@ module.exports = function(RED) {
if (msg.attachments) {
if (!Array.isArray(msg.attachments)) { sendopts.attachments = [ msg.attachments ]; }
else { sendopts.attachments = msg.attachments; }
- for (var a=0; a < sendopts.attachments.length; a++) {
- if (sendopts.attachments[a].hasOwnProperty("content")) {
- if (typeof sendopts.attachments[a].content !== "string" && !Buffer.isBuffer(sendopts.attachments[a].content)) {
+ for (const attachment of sendopts.attachments) {
+ if (attachment.hasOwnProperty('content')) {
+ if (typeof attachment.content !== 'string' && !Buffer.isBuffer(attachment.content)) {
node.error(RED._("email.errors.invalidattachment"),msg);
node.status({fill:"red",shape:"ring",text:"email.status.sendfail"});
return;
@@ -194,7 +192,7 @@ module.exports = function(RED) {
else { node.warn(RED._("email.errors.nopayload")); }
});
}
- RED.nodes.registerType("e-mail",EmailNode,{
+ RED.nodes.registerType("e-mail", EmailNode, {
credentials: {
userid: {type:"text"},
password: {type: "password"},
diff --git a/social/email/README.md b/social/email/README.md
index 16b2b516..3ca80315 100644
--- a/social/email/README.md
+++ b/social/email/README.md
@@ -35,7 +35,7 @@ or enable Details on how to do this can be found here.
Usage
@@ -71,7 +71,7 @@ address (userxx@some_domain.com), you may see *(No Sender)* in the email.
The payload can be html format. You can also specify `msg.plaintext` if the main payload is html.
-If the payload is a binary buffer then it will be converted to an attachment.
+If the payload is a binary buffer, then it will be converted to an attachment.
The filename should be set using `msg.filename`. Optionally
`msg.description` can be added for the body text.
@@ -86,3 +86,51 @@ If you have own signed certificates, Nodemailer can complain about that and refu
Use secure connection - If enabled the connection will use TLS when connecting to server. If disabled then TLS is used if server supports the STARTTLS extension. In most cases set this to enabled if you are connecting to port 465. For port 587 or 25 keep it disabled.
This node uses the *nodemailer* npm module.
+
+Testing
+-----
+
+You can pass the credentials object to the `node-red-node-test-helper` by doing the following:
+
+```js
+const emailNode = require("./61-email");
+
+const testFlows = [{
+ id: "n1", type: "e-mail", name: "Email",
+ from: "email1test@example.com", subject: "TestSubject", server: "testServer",
+ port: "1111", secure: "X", tls: true, authtype: "BASIC",
+}];
+
+const testCredentials = {
+ n1: {
+ userid: "ExampleUser",
+ password: "ExamplePassword",
+ global: false
+ }
+};
+
+it('should be loaded', function (done) {
+ helper.load(emailNode, testFlows, testCredentials, function () {
+ const n1 = helper.getNode("n1");
+ try {
+ n1.should.have.property('name', 'Email');
+ n1.should.have.property('from', 'email1test@example.com');
+ n1.should.have.property('subject', 'TestSubject');
+ n1.should.have.property('outserver', 'testServer'); // Gathered via server
+ n1.should.have.property('outport', '1111'); // Gathered via port
+ n1.should.have.property('secure', 'X');
+ n1.should.have.property('tls', true);
+ n1.should.have.property('authtype', 'BASIC');
+ n1.should.have.property('credentials');
+ n1.should.have.property('credentials', {
+ userid: "ExampleUser",
+ password: "ExamplePassword",
+ global: false
+ });
+ done();
+ } catch (err) {
+ done(err);
+ }
+ });
+});
+```