mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Improvements and fixes for 61-email component (#1075)
* 61-email: fix useTLS and its span in HTML. Removes unused code in 61-email.js. Adds description on how to test the entity * 61-email: fix useTLS and its span in HTML. Removes unused code in 61-email.js. Adds description on how to test the entity
This commit is contained in:
parent
35c4061748
commit
45d4fd0b08
@ -70,7 +70,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<div class="form-row node-input-useTLS">
|
<div class="form-row node-input-useTLS">
|
||||||
<label for="node-input-useTLS"><i class="fa fa-lock"></i> <span data-i18n="email.label.useTLS"></label>
|
<label for="node-input-tls"><i class="fa fa-lock"></i> <span data-i18n="email.label.useTLS"></span></label>
|
||||||
<input type="checkbox" id="node-input-tls" style="display:inline-block; width:20px; vertical-align:baseline;">
|
<input type="checkbox" id="node-input-tls" style="display:inline-block; width:20px; vertical-align:baseline;">
|
||||||
<span data-i18n="email.label.rejectUnauthorised"></span>
|
<span data-i18n="email.label.rejectUnauthorised"></span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -14,7 +14,6 @@ const { domainToUnicode } = require("url");
|
|||||||
|
|
||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var util = require("util");
|
|
||||||
var Imap = require('imap');
|
var Imap = require('imap');
|
||||||
var Pop3Command = require("node-pop3");
|
var Pop3Command = require("node-pop3");
|
||||||
var nodemailer = require("nodemailer");
|
var nodemailer = require("nodemailer");
|
||||||
@ -34,7 +33,7 @@ module.exports = function(RED) {
|
|||||||
this.outserver = n.server;
|
this.outserver = n.server;
|
||||||
this.outport = n.port;
|
this.outport = n.port;
|
||||||
this.secure = n.secure;
|
this.secure = n.secure;
|
||||||
this.tls = true;
|
this.tls = n.tls;
|
||||||
this.authtype = n.authtype || "BASIC";
|
this.authtype = n.authtype || "BASIC";
|
||||||
if (this.authtype !== "BASIC") {
|
if (this.authtype !== "BASIC") {
|
||||||
this.inputs = 1;
|
this.inputs = 1;
|
||||||
@ -62,7 +61,6 @@ module.exports = function(RED) {
|
|||||||
this.error(RED._("email.errors.notoken"));
|
this.error(RED._("email.errors.notoken"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (n.tls === false) { this.tls = false; }
|
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
var smtpOptions = {
|
var smtpOptions = {
|
||||||
@ -87,9 +85,9 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.on("input", function(msg, send, done) {
|
this.on("input", function(msg, send, done) {
|
||||||
|
|
||||||
if (node.authtype === "XOAUTH2") {
|
if (node.authtype === "XOAUTH2") {
|
||||||
if (node.token) {
|
if (node.token) {
|
||||||
|
var saslxoauth2 = "";
|
||||||
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) {
|
||||||
@ -119,7 +117,7 @@ module.exports = function(RED) {
|
|||||||
node.warn(RED._("node-red:common.errors.nooverride"));
|
node.warn(RED._("node-red:common.errors.nooverride"));
|
||||||
}
|
}
|
||||||
var sendopts = { from: ((msg.from) ? msg.from : node.userid) }; // sender address
|
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 === "") {
|
if (node.name === "") {
|
||||||
sendopts.cc = msg.cc;
|
sendopts.cc = msg.cc;
|
||||||
sendopts.bcc = msg.bcc;
|
sendopts.bcc = msg.bcc;
|
||||||
@ -167,9 +165,9 @@ module.exports = function(RED) {
|
|||||||
if (msg.attachments) {
|
if (msg.attachments) {
|
||||||
if (!Array.isArray(msg.attachments)) { sendopts.attachments = [ msg.attachments ]; }
|
if (!Array.isArray(msg.attachments)) { sendopts.attachments = [ msg.attachments ]; }
|
||||||
else { sendopts.attachments = msg.attachments; }
|
else { sendopts.attachments = msg.attachments; }
|
||||||
for (var a=0; a < sendopts.attachments.length; a++) {
|
for (const attachment of sendopts.attachments) {
|
||||||
if (sendopts.attachments[a].hasOwnProperty("content")) {
|
if (attachment.hasOwnProperty('content')) {
|
||||||
if (typeof sendopts.attachments[a].content !== "string" && !Buffer.isBuffer(sendopts.attachments[a].content)) {
|
if (typeof attachment.content !== 'string' && !Buffer.isBuffer(attachment.content)) {
|
||||||
node.error(RED._("email.errors.invalidattachment"),msg);
|
node.error(RED._("email.errors.invalidattachment"),msg);
|
||||||
node.status({fill:"red",shape:"ring",text:"email.status.sendfail"});
|
node.status({fill:"red",shape:"ring",text:"email.status.sendfail"});
|
||||||
return;
|
return;
|
||||||
@ -194,7 +192,7 @@ module.exports = function(RED) {
|
|||||||
else { node.warn(RED._("email.errors.nopayload")); }
|
else { node.warn(RED._("email.errors.nopayload")); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("e-mail",EmailNode,{
|
RED.nodes.registerType("e-mail", EmailNode, {
|
||||||
credentials: {
|
credentials: {
|
||||||
userid: {type:"text"},
|
userid: {type:"text"},
|
||||||
password: {type: "password"},
|
password: {type: "password"},
|
||||||
|
@ -35,7 +35,7 @@ or enable <a target="_new" href="https://support.google.com/accounts/answer/6010
|
|||||||
Office 365 users
|
Office 365 users
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
If you are accessing Exchnage you will need to register an application through their platform and use OAuth2.0.
|
If you are accessing Exchange you will need to register an application through their platform and use OAuth2.0.
|
||||||
<a target="_new" href="https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#get-an-access-token">Details on how to do this can be found here.</a>
|
<a target="_new" href="https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#get-an-access-token">Details on how to do this can be found here.</a>
|
||||||
|
|
||||||
Usage
|
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.
|
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
|
The filename should be set using `msg.filename`. Optionally
|
||||||
`msg.description` can be added for the body text.
|
`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.
|
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.
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user