0

I'm validating the email with smtp server connection using rcpt command. It is working fine with google but when I try with outlook and yahoo email it shows "SMTP connection error: Connection unexpectedly closed "

my code is here

def check_smtp(self, email):
    host = socket.gethostname()
    server = smtplib.SMTP(port=self.smtp_port_number, timeout=self.connection_timeout)
    server.set_debuglevel(100)
    server.connect(self.get_MX_records(email.split('@')[1]))
    server.helo(host)
    server.mail('[email protected]')
    code, message = server.rcpt(str(email))
    server.quit()
    if code == 250:
        return True
    else:
        return False

Here is my input {"email": "[email protected]"}

2
  • 1
    Most SMTP servers block connections from random clients. You should send the email through your ISP's relay. Commented May 23, 2024 at 20:31
  • 1
    Spammers abused this in the 1990s so it's turned off most places anyway. Probably they think you're a spammer, too. Commented May 23, 2024 at 20:32

1 Answer 1

0

It's likely because your IP is blacklisted or the SMTP handshake is not being established properly.

You can try using your home network; it might work.

Since I have developed an email verification API tool, I occasionally encounter these kinds of issues as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.