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>
|
||||
<br/>
|
||||
<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;">
|
||||
<span data-i18n="email.label.rejectUnauthorised"></span>
|
||||
</div>
|
||||
|
@ -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;
|
||||
|
@ -35,7 +35,7 @@ or enable <a target="_new" href="https://support.google.com/accounts/answer/6010
|
||||
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>
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user