mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-22 04:21:32 +02:00
Co-authored-by: Charlie Kolb <charlie@n8n.io> Co-authored-by: Guillaume Jacquart <jacquart.guillaume@gmail.com> Co-authored-by: Stephen Wright <sjw948@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Bernhard Wittmann <bernhard.wittmann@n8n.io> Co-authored-by: Nikhil Kuriakose <nikhil.kuriakose@n8n.io> Co-authored-by: Albert Alises <albert.alises@gmail.com> Co-authored-by: Michael Kret <88898367+michael-radency@users.noreply.github.com> Co-authored-by: Andreas Fitzek <andreas.fitzek@n8n.io> Co-authored-by: Elias Meire <elias@meire.dev> Co-authored-by: Robin Braumann <50590409+bjorger@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: yehorkardash <yehor.kardash@n8n.io> Co-authored-by: Mike Repeć <mike.repec@n8n.io> Co-authored-by: Yuliia Pominchuk <31064937+yuliia-pominchuk@users.noreply.github.com> Co-authored-by: RomanDavydchuk <roman.davydchuk@n8n.io>
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import type {
|
|
IDataObject,
|
|
ICredentialsDecrypted,
|
|
ICredentialTestFunctions,
|
|
INodeCredentialTestResult,
|
|
} from 'n8n-workflow';
|
|
import { createTransport } from 'nodemailer';
|
|
import type SMTPTransport from 'nodemailer/lib/smtp-transport';
|
|
|
|
export type EmailSendOptions = {
|
|
appendAttribution?: boolean;
|
|
allowUnauthorizedCerts?: boolean;
|
|
attachments?: string;
|
|
fileAttachments?: string;
|
|
ccEmail?: string;
|
|
bccEmail?: string;
|
|
replyTo?: string;
|
|
};
|
|
|
|
export function configureTransport(credentials: IDataObject, options: EmailSendOptions) {
|
|
const connectionOptions: SMTPTransport.Options = {
|
|
host: credentials.host as string,
|
|
port: credentials.port as number,
|
|
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;
|
|
}
|
|
|
|
if (credentials.user || credentials.password) {
|
|
connectionOptions.auth = {
|
|
user: credentials.user as string,
|
|
pass: credentials.password as string,
|
|
};
|
|
}
|
|
|
|
if (options.allowUnauthorizedCerts === true) {
|
|
connectionOptions.tls = {
|
|
rejectUnauthorized: false,
|
|
};
|
|
}
|
|
|
|
return createTransport(connectionOptions, {
|
|
disableFileAccess: true,
|
|
disableUrlAccess: true,
|
|
});
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|