接入教程
1. 访问Mailboxlayer官网注册账户获取API密钥。2. 使用提供的API端点构造请求URL,包含access_key和email参数。3. 发送HTTP GET请求至验证端点。4. 解析返回的JSON响应,根据字段判断邮箱有效性、质量和可送达性。
Python验证邮箱地址
python
import requests
url = 'https://apilayer.net/api/check'
params = {
'access_key': 'YOUR_API_KEY',
'email': 'test@example.com'
}
response = requests.get(url, params=params)
data = response.json()
if data['mx_found'] and data['smtp_check']:
print('邮箱验证通过')
else:
print('邮箱验证失败')
PHP邮箱验证示例
php
<?php
$url = 'https://apilayer.net/api/check';
$params = [
'access_key' => 'YOUR_API_KEY',
'email' => 'test@example.com'
];
$ch = curl_init($url . '?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if ($data['mx_found'] && $data['smtp_check']) {
echo '邮箱验证通过';
} else {
echo '邮箱验证失败';
}
?>
JavaScript邮箱验证
javascript
const url = 'https://apilayer.net/api/check';
const params = new URLSearchParams({
access_key: 'YOUR_API_KEY',
email: 'test@example.com'
});
fetch(`${url}?${params}`)
.then(response => response.json())
.then(data => {
if (data.mx_found && data.smtp_check) {
console.log('邮箱验证通过');
} else {
console.log('邮箱验证失败');
}
})
.catch(error => console.error('请求失败:', error));
常见问题
如何获取API密钥?
访问Mailboxlayer官网注册账号,在控制台页面可以创建和管理API密钥。免费套餐提供有限的请求次数。
API支持哪些验证功能?
支持语法检查、MX记录验证、SMTP实时验证、免费邮箱检测、一次性邮箱过滤、角色邮箱识别等功能。
验证响应包含哪些信息?
响应包含邮箱格式有效性、MX记录状态、SMTP验证结果、是否免费邮箱、是否一次性邮箱、风险评分等字段。
Aitishiku.com