Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Helo problems with Spamhaus #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deep-email-validator",
"version": "0.1.22",
"version": "0.1.23",
"files": [
"dist/**/*"
],
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Options = {
validateTypo: boolean
validateDisposable: boolean
validateSMTP: boolean
helo?: string
}

type MailCheckOptions = {
Expand Down
9 changes: 7 additions & 2 deletions src/smtp/smtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ const log = (...args: unknown[]) => {
}
}

export const checkSMTP = async (sender: string, recipient: string, exchange: string): Promise<OutputFormat> => {
export const checkSMTP = async (
sender: string,
recipient: string,
exchange: string,
helo?: string
): Promise<OutputFormat> => {
const timeout = 1000 * 10 // 10 seconds
return new Promise(r => {
let receivedData = false
Expand Down Expand Up @@ -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) {
Expand Down