mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
feat(Send Email Node): Smtp credential improvements (#10147)
This commit is contained in:
parent
ada1256898
commit
dc13ceb416
|
@ -41,6 +41,17 @@ export class Smtp implements ICredentialType {
|
|||
type: 'boolean',
|
||||
default: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Disable STARTTLS',
|
||||
name: 'disableStartTls',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
secure: [false],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Client Host Name',
|
||||
name: 'hostName',
|
||||
|
|
|
@ -26,6 +26,7 @@ const versionDescription: INodeTypeDescription = {
|
|||
{
|
||||
name: 'smtp',
|
||||
required: true,
|
||||
testedBy: 'smtpConnectionTest',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
|
@ -70,6 +71,10 @@ export class EmailSendV2 implements INodeType {
|
|||
};
|
||||
}
|
||||
|
||||
methods = {
|
||||
credentialTest: { smtpConnectionTest: send.smtpConnectionTest },
|
||||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
let returnData: INodeExecutionData[][] = [];
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import type {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
JsonObject,
|
||||
|
@ -210,6 +213,10 @@ function configureTransport(credentials: IDataObject, options: EmailSendOptions)
|
|||
secure: credentials.secure as boolean,
|
||||
};
|
||||
|
||||
if (credentials.secure === false) {
|
||||
connectionOptions.ignoreTLS = credentials.disableStartTls as boolean;
|
||||
}
|
||||
|
||||
if (typeof credentials.hostName === 'string' && credentials.hostName) {
|
||||
connectionOptions.name = credentials.hostName;
|
||||
}
|
||||
|
@ -230,6 +237,28 @@ function configureTransport(credentials: IDataObject, options: EmailSendOptions)
|
|||
return createTransport(connectionOptions);
|
||||
}
|
||||
|
||||
export async function smtpConnectionTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data!;
|
||||
const transporter = configureTransport(credentials, {});
|
||||
try {
|
||||
await transporter.verify();
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Connection successful!',
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: error.message,
|
||||
};
|
||||
} finally {
|
||||
transporter.close();
|
||||
}
|
||||
}
|
||||
|
||||
export async function execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const items = this.getInputData();
|
||||
const nodeVersion = this.getNode().typeVersion;
|
||||
|
|
Loading…
Reference in a new issue