Make it possible to use email nodes work with unauthorized certs

This commit is contained in:
Jan Oberhauser 2019-10-25 21:38:54 +02:00
parent 02491775b6
commit 547f245947
2 changed files with 55 additions and 6 deletions

View file

@ -8,7 +8,7 @@ import {
ITriggerResponse, ITriggerResponse,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { connect as imapConnect, ImapSimple, getParts, Message } from 'imap-simple'; import { connect as imapConnect, ImapSimple, ImapSimpleOptions, getParts, Message } from 'imap-simple';
export class EmailReadImap implements INodeType { export class EmailReadImap implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@ -75,6 +75,22 @@ export class EmailReadImap implements INodeType {
}, },
description: 'Prefix for name of the binary property to which to<br />write the attachments. An index starting with 0 will be added.<br />So if name is "attachment_" the first attachment is saved to "attachment_0"', description: 'Prefix for name of the binary property to which to<br />write the attachments. An index starting with 0 will be added.<br />So if name is "attachment_" the first attachment is saved to "attachment_0"',
}, },
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Ignore SSL Issues',
name: 'allowUnauthorizedCerts',
type: 'boolean',
default: false,
description: 'Do connect even if SSL certificate validation is not possible.',
},
],
},
], ],
}; };
@ -90,6 +106,7 @@ export class EmailReadImap implements INodeType {
const mailbox = this.getNodeParameter('mailbox') as string; const mailbox = this.getNodeParameter('mailbox') as string;
const postProcessAction = this.getNodeParameter('postProcessAction') as string; const postProcessAction = this.getNodeParameter('postProcessAction') as string;
const downloadAttachments = this.getNodeParameter('downloadAttachments') as boolean; const downloadAttachments = this.getNodeParameter('downloadAttachments') as boolean;
const options = this.getNodeParameter('options', {}) as IDataObject;
// Returns the email text // Returns the email text
@ -219,7 +236,7 @@ export class EmailReadImap implements INodeType {
let connection: ImapSimple; let connection: ImapSimple;
const config = { const config: ImapSimpleOptions = {
imap: { imap: {
user: credentials.user as string, user: credentials.user as string,
password: credentials.password as string, password: credentials.password as string,
@ -237,6 +254,12 @@ export class EmailReadImap implements INodeType {
}, },
}; };
if (options.allowUnauthorizedCerts === true) {
config.imap.tlsOptions = {
rejectUnauthorized: false
};
}
// Connect to the IMAP server and open the mailbox // Connect to the IMAP server and open the mailbox
// that we get informed whenever a new email arrives // that we get informed whenever a new email arrives
connection = await imapConnect(config); connection = await imapConnect(config);

View file

@ -3,13 +3,14 @@ import {
IExecuteSingleFunctions, IExecuteSingleFunctions,
} from 'n8n-core'; } from 'n8n-core';
import { import {
IDataObject,
INodeTypeDescription, INodeTypeDescription,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { createTransport } from 'nodemailer'; import { createTransport } from 'nodemailer';
import SMTPTransport = require('nodemailer/lib/smtp-transport');
export class EmailSend implements INodeType { export class EmailSend implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@ -96,6 +97,22 @@ export class EmailSend implements INodeType {
default: '', default: '',
description: 'Name of the binary properties which contain<br />data which should be added to email as attachment.<br />Multiple ones can be comma separated.', description: 'Name of the binary properties which contain<br />data which should be added to email as attachment.<br />Multiple ones can be comma separated.',
}, },
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Ignore SSL Issues',
name: 'allowUnauthorizedCerts',
type: 'boolean',
default: false,
description: 'Do connect even if SSL certificate validation is not possible.',
},
],
},
], ],
}; };
@ -110,6 +127,7 @@ export class EmailSend implements INodeType {
const text = this.getNodeParameter('text') as string; const text = this.getNodeParameter('text') as string;
const html = this.getNodeParameter('html') as string; const html = this.getNodeParameter('html') as string;
const attachmentPropertyString = this.getNodeParameter('attachments') as string; const attachmentPropertyString = this.getNodeParameter('attachments') as string;
const options = this.getNodeParameter('options', {}) as IDataObject;
const credentials = this.getCredentials('smtp'); const credentials = this.getCredentials('smtp');
@ -117,16 +135,24 @@ export class EmailSend implements INodeType {
throw new Error('No credentials got returned!'); throw new Error('No credentials got returned!');
} }
const transporter = createTransport({ const connectionOptions: SMTPTransport.Options = {
// @ts-ignore
host: credentials.host as string, host: credentials.host as string,
port: credentials.port as number, port: credentials.port as number,
secure: credentials.secure as boolean, secure: credentials.secure as boolean,
// @ts-ignore
auth: { auth: {
user: credentials.user, user: credentials.user,
pass: credentials.password, pass: credentials.password,
} }
}); };
if (options.allowUnauthorizedCerts === true) {
connectionOptions.tls = {
rejectUnauthorized: false
};
}
const transporter = createTransport(connectionOptions);
// setup email data with unicode symbols // setup email data with unicode symbols
const mailOptions = { const mailOptions = {