diff --git a/packages/nodes-base/credentials/Smtp.credentials.ts b/packages/nodes-base/credentials/Smtp.credentials.ts index 28817bdc88..d14c832699 100644 --- a/packages/nodes-base/credentials/Smtp.credentials.ts +++ b/packages/nodes-base/credentials/Smtp.credentials.ts @@ -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', diff --git a/packages/nodes-base/nodes/EmailSend/v2/EmailSendV2.node.ts b/packages/nodes-base/nodes/EmailSend/v2/EmailSendV2.node.ts index 5c9e653c48..ec162c31b0 100644 --- a/packages/nodes-base/nodes/EmailSend/v2/EmailSendV2.node.ts +++ b/packages/nodes-base/nodes/EmailSend/v2/EmailSendV2.node.ts @@ -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 { let returnData: INodeExecutionData[][] = []; diff --git a/packages/nodes-base/nodes/EmailSend/v2/send.operation.ts b/packages/nodes-base/nodes/EmailSend/v2/send.operation.ts index b60eb689e5..fe733e0a02 100644 --- a/packages/nodes-base/nodes/EmailSend/v2/send.operation.ts +++ b/packages/nodes-base/nodes/EmailSend/v2/send.operation.ts @@ -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 { + 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 { const items = this.getInputData(); const nodeVersion = this.getNode().typeVersion;