python - 检查python中是否存在电子邮件地址
问题描述
我想检查 python 2.7 中是否存在电子邮件地址。我使用了 SMTP 服务器,但它没有返回任何结果。有谁知道检查电子邮件地址是否存在?
try:
email_address = 'me@exemple.com'
domain_name = email_address.split('@')[1]
records = dns.resolver.query(domain_name, 'MX')
mxRecord = records[0].exchange
mxRecord = str(mxRecord)
#Step 3: ping email server
#check if the email address exists
# Get local server hostname
host = socket.gethostname()
# SMTP lib setup (use debug level for full output)
server = smtplib.SMTP()
server.set_debuglevel(0)
# SMTP Conversation
server.connect(mxRecord)
server.helo(host)
server.mail('me@domain.com')
code, message = server.rcpt(str(addressToVerify))
server.quit()
print(code)
# Assume 250 as Success
if code == 250:
print('Y')
else:
print('N')
except Exception as error:
print('Erreur:'+repr(error))
解决方案
推荐阅读
- php - 修改 WooCommerce 存档产品页面以显示每个产品的 SKU
- c# - 使用 Renci SshNet 运行命令时客户端崩溃
- interface - 为模块声明接口时 SystemVerilog 编译错误(未声明的标识符 [12.5(IEEE)])
- mongodb - Prisma-docker 无法连接到服务器
- flutter - 应用程序在真实的 iOS 设备上无法运行(黑屏),但在 iOS 模拟器中完美运行
- amazon-dynamodb - 是否可以在 DynamoDB 中设置基于标签的查询系统?
- python - 如何使用 ShopifyAPI 将商品成本添加到产品变体?
- laravel - 无法访问 GraphQL 服务器状态码 500
- vue.js - VueJs 为日期格式创建指令
- node.js - 如何从节点服务器获取数据