i need script python scanner email valid or not
Here is a Python script that can scan and validate email addresses:
import re
import smtplib
def validate_email(email):
# Checking the email pattern
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
if not re.match(pattern, email):
return False
# Checking if the email is valid
try:
domain = email.split('@')[1]
smtp = smtplib.SMTP(domain, timeout=5)
status, message = smtp.ehlo()
if not status == 250:
return False
smtp.quit()
return True
except:
return False
# Testing the function
email1 = 'example@gmail.com'
email2 = 'example@invalid'
email3 = 'example@outlook.com'
print(validate_email(email1))
print(validate_email(email2))
print(validate_email(email3))
In this script, the validate_email function takes an email address as input and returns True if the email is valid and False if it is not.
First, it checks whether the email matches the standard pattern using a regular expression. If it doesn't match, it returns False.
If the email matches the pattern, the script then attempts to validate the email by checking if the domain exists and can be reached through an SMTP connection. If the connection is successful, the function returns True. If not, it returns False.
The script includes a test of the validate_email function using three example email addresses.
Note: This script is for educational purposes only and should not be used for malicious purposes.
原文地址: https://www.cveoy.top/t/topic/D4M 著作权归作者所有。请勿转载和采集!