ping-email icon indicating copy to clipboard operation
ping-email copied to clipboard

SMTP TImeout issue

Open suryanshsingh2001 opened this issue 1 year ago • 0 comments

I keep getting this message on every email. For reference, I used a express node app

import express from 'express';
import { PingEmail } from 'ping-email';


// Create an Express application
const app = express();
const port = 3000;

// Configure the PingEmail instance
const pingEmail = new PingEmail({
    port: 267, // SMTP port
    timeout: 15000, // Time in milliseconds to wait for a response from the SMTP server
    attempts: 5, // Number of attempts to verify the email address
});

// Middleware to parse JSON request bodies
app.use(express.json());

// Endpoint to validate an email address
app.post('/validate-email', async (req, res) => {
    const { email } = req.body;
    
    if (!email) {
        return res.status(400).json({ error: 'Email is required' });
    }

    try {
        console.log("Validating Email:", email);

        const { email: verifiedEmail, valid, message } = await pingEmail.ping(email);

        console.log("Validation Result:", { verifiedEmail, valid, message });

        const result = {
            email: verifiedEmail,
            valid: valid,
            reason: message
        };

        res.json(result);
    } catch (error) {
        console.error('Error during email validation:', error);
        res.status(500).json({ error: 'Internal Server Error' });
    }
});

// Start the server
app.listen(port, () => {
    console.log(`Email validation service is running on port ${port}`);
});

Here is the response I get on running npm start

Validating Email: [email protected]
Validation Result: {
  verifiedEmail: '[email protected]',
  valid: false,
  message: 'Connection timeout'}

suryanshsingh2001 avatar Jul 29 '24 11:07 suryanshsingh2001