域名邮箱批量查询系统是一种工具或服务,用于批量验证和查询特定域名下的电子邮件地址的有效性。这种系统通常通过检查域名MX记录、SMTP服务器响应等方式来确定邮箱是否存在和可用。
import dns.resolver
import requests
def query_mx_records(domain):
try:
answers = dns.resolver.resolve(domain, 'MX')
mx_records = []
for rdata in answers:
mx_records.append(rdata.exchange.to_text())
return mx_records
except dns.resolver.NXDOMAIN:
return f"Domain {domain} does not exist."
except dns.resolver.NoAnswer:
return f"No MX records found for domain {domain}."
except dns.resolver.Timeout:
return f"Query timed out for domain {domain}."
def check_email_exists(email):
domain = email.split('@')[1]
mx_records = query_mx_records(domain)
if isinstance(mx_records, str):
return mx_records
for mx in mx_records:
try:
response = requests.get(f"http://api.mailtester.com/check?email={email}")
if response.json().get('status') == 'valid':
return f"{email} is valid."
except requests.RequestException as e:
continue
return f"{email} is invalid or not reachable."
# 示例使用
email_list = ["example1@example.com", "example2@example.com"]
for email in email_list:
print(check_email_exists(email))
领取专属 10元无门槛券
手把手带您无忧上云