Skip to content
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 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.port, options.timeout)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/options/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const defaultOptions: ValidatorOptionsFinal = {
email: '[email protected]',
sender: '[email protected]',
timeout: 10 * 1000,
port: 25,
validateRegex: true,
validateMx: true,
validateTypo: true,
Expand All @@ -10,6 +12,8 @@ const defaultOptions: ValidatorOptionsFinal = {

type Options = {
sender: string
port: number
timeout: number
validateRegex: boolean
validateMx: boolean
validateTypo: boolean
Expand Down
11 changes: 8 additions & 3 deletions src/smtp/smtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ const log = (...args: unknown[]) => {
}
}

export const checkSMTP = async (sender: string, recipient: string, exchange: string): Promise<OutputFormat> => {
const timeout = 1000 * 10 // 10 seconds
export const checkSMTP = async (
sender: string,
recipient: string,
exchange: string,
port: number,
timeout: number
): Promise<OutputFormat> => {
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 => {
Expand Down