From bccf2161f9ad78d0bb28867ce6ccda8f016198c5 Mon Sep 17 00:00:00 2001 From: Gaurav Nanda Date: Wed, 12 Apr 2023 12:46:17 +0530 Subject: [PATCH] Fix Helo problems with Spamhaus --- package.json | 2 +- src/index.ts | 2 +- src/options/options.ts | 1 + src/smtp/smtp.ts | 9 +++++++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f85d901..eb36396 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deep-email-validator", - "version": "0.1.22", + "version": "0.1.23", "files": [ "dist/**/*" ], diff --git a/src/index.ts b/src/index.ts index e7b27ea..94810d3 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.helo) } } diff --git a/src/options/options.ts b/src/options/options.ts index 1fb46ce..814c423 100644 --- a/src/options/options.ts +++ b/src/options/options.ts @@ -15,6 +15,7 @@ type Options = { validateTypo: boolean validateDisposable: boolean validateSMTP: boolean + helo?: string } type MailCheckOptions = { diff --git a/src/smtp/smtp.ts b/src/smtp/smtp.ts index 9aeb07c..4e561b0 100644 --- a/src/smtp/smtp.ts +++ b/src/smtp/smtp.ts @@ -8,7 +8,12 @@ const log = (...args: unknown[]) => { } } -export const checkSMTP = async (sender: string, recipient: string, exchange: string): Promise => { +export const checkSMTP = async ( + sender: string, + recipient: string, + exchange: string, + helo?: string +): Promise => { const timeout = 1000 * 10 // 10 seconds return new Promise(r => { let receivedData = false @@ -48,7 +53,7 @@ export const checkSMTP = async (sender: string, recipient: string, exchange: str r(createOutput()) }) - const commands = [`helo ${exchange}\r\n`, `mail from: <${sender}>\r\n`, `rcpt to: <${recipient}>\r\n`] + const commands = [`helo ${helo || exchange}\r\n`, `mail from: <${sender}>\r\n`, `rcpt to: <${recipient}>\r\n`] let i = 0 socket.on('next', () => { if (i < 3) {