diff --git a/src/index.ts b/src/index.ts index e7b27ea..8324fd7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,7 @@ export async function validate(emailOrOptions: string | ValidatorOptions): Promi const mx = await getBestMx(domain) if (!mx) return createOutput('mx', 'MX record not found') if (options.validateSMTP) { - return checkSMTP(options.sender, email, mx.exchange) + return checkSMTP(options.sender, email, mx.exchange, options.port, options.timeout) } } diff --git a/src/options/options.ts b/src/options/options.ts index 1fb46ce..561e512 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -1,6 +1,8 @@ const defaultOptions: ValidatorOptionsFinal = { email: 'name@example.org', sender: 'name@example.org', + timeout: 10 * 1000, + port: 25, validateRegex: true, validateMx: true, validateTypo: true, @@ -10,6 +12,8 @@ const defaultOptions: ValidatorOptionsFinal = { type Options = { sender: string + port: number + timeout: number validateRegex: boolean validateMx: boolean validateTypo: boolean diff --git a/src/smtp/smtp.ts b/src/smtp/smtp.ts index 9aeb07c..6e65dbc 100644 --- a/src/smtp/smtp.ts +++ b/src/smtp/smtp.ts @@ -8,12 +8,17 @@ const log = (...args: unknown[]) => { } } -export const checkSMTP = async (sender: string, recipient: string, exchange: string): Promise => { - const timeout = 1000 * 10 // 10 seconds +export const checkSMTP = async ( + sender: string, + recipient: string, + exchange: string, + port: number, + timeout: number +): Promise => { return new Promise(r => { let receivedData = false let closed = false - const socket = net.createConnection(25, exchange) + const socket = net.createConnection(port, exchange) socket.setEncoding('ascii') socket.setTimeout(timeout) socket.on('error', error => {