EmailVerify LogoEmailVerify

Droid

Email checker with Droid CLI. Verify emails in Droid AI assistant.

Droid 是一个面向开发者的 AI 驱动终端助手。了解如何在 Droid 工作流中集成 EmailVerify 进行邮箱验证。

什么是 Droid?

Droid 是一个现代 AI 终端助手,提供:

  • 智能命令建议
  • 代码生成和解释
  • Shell 自动化
  • 多模型支持(GPT-4, Claude, 本地模型)

设置

安装 EmailVerify CLI

npm install -g @emailverify/cli
bv config set api-key YOUR_API_KEY

环境设置

export EMAILVERIFY_API_KEY=your-api-key

使用 Droid

快速验证

您: 使用 emailverify 验证 john@example.com

Droid:

运行: bv verify john@example.com --json

{
  "email": "john@example.com",
  "status": "valid",
  "score": 0.88,
  "result": {
    "deliverable": true,
    "disposable": false,
    "role": false
  }
}

✅ 邮箱有效(88% 置信度)

批量操作

您: 验证 contacts.csv 中的所有邮箱并创建报告

Droid:

我会处理 CSV 并验证每个邮箱。

读取 contacts.csv... 找到 250 条记录。

进度: ████████████████████ 100%

摘要报告:
┌──────────────┬───────┬────────┐
│ 状态         │ 数量  │ %      │
├──────────────┼───────┼────────┤
│ 有效         │ 198   │ 79.2%  │
│ 无效         │ 32    │ 12.8%  │
│ 未知         │ 12    │ 4.8%   │
│ 一次性       │ 8     │ 3.2%   │
└──────────────┴───────┴────────┘

生成的文件:
- contacts_valid.csv (198 个邮箱)
- contacts_invalid.csv (32 个邮箱)
- contacts_review.csv (20 个邮箱)

您想让我解释任何无效邮箱吗?

代码生成

您: 创建一个用于邮箱验证的 Node.js API 端点

Droid:

// routes/verify.ts
import { Router } from 'express';
import rateLimit from 'express-rate-limit';

const router = Router();

// 速率限制:每分钟 100 次请求
const limiter = rateLimit({
  windowMs: 60 * 1000,
  max: 100,
  message: { error: '请求过多' }
});

router.post('/verify', limiter, async (req, res) => {
  const { email } = req.body;

  if (!email) {
    return res.status(400).json({ error: '邮箱地址是必需的' });
  }

  try {
    const response = await fetch('https://api.emailverify.ai/v1/verify', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.EMAILVERIFY_API_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ email }),
    });

    const result = await response.json();

    return res.json({
      email,
      isValid: result.status === 'valid',
      score: result.score,
      flags: {
        disposable: result.result.disposable,
        role: result.result.role,
      }
    });
  } catch (error) {
    return res.status(500).json({ error: '验证服务不可用' });
  }
});

export default router;

已保存到 routes/verify.ts

Shell 自动化

您: 创建一个每日验证新注册用户的 cron 任务

Droid:

# 创建验证脚本
cat > /usr/local/bin/verify-daily-signups.sh << 'EOF'
#!/bin/bash
set -e

LOG_FILE="/var/log/email-verification.log"
DB_HOST="${DB_HOST:-localhost}"
DB_NAME="${DB_NAME:-myapp}"

echo "$(date): 开始每日邮箱验证" >> $LOG_FILE

# 从数据库获取未验证的邮箱
emails=$(psql -h $DB_HOST -d $DB_NAME -t -c \
  "SELECT email FROM users WHERE email_verified IS NULL AND created_at > NOW() - INTERVAL '1 day'")

count=0
invalid=0

for email in $emails; do
  result=$(bv verify "$email" --json 2>/dev/null)
  status=$(echo "$result" | jq -r '.status')

  if [ "$status" = "valid" ]; then
    psql -h $DB_HOST -d $DB_NAME -c \
      "UPDATE users SET email_verified = true WHERE email = '$email'"
  else
    psql -h $DB_HOST -d $DB_NAME -c \
      "UPDATE users SET email_verified = false, email_status = '$status' WHERE email = '$email'"
    ((invalid++))
  fi
  ((count++))

  sleep 0.1  # 速率限制
done

echo "$(date): 已验证 $count 个邮箱,$invalid 个无效" >> $LOG_FILE
EOF

chmod +x /usr/local/bin/verify-daily-signups.sh

# 添加到 crontab(每天凌晨 2 点运行)
(crontab -l 2>/dev/null; echo "0 2 * * * /usr/local/bin/verify-daily-signups.sh") | crontab -

echo "✅ Cron 任务已创建。将在每天凌晨 2 点运行。"

集成测试

您: 编写邮箱验证的集成测试

Droid:

// __tests__/email-verification.test.ts
import { describe, it, expect, beforeAll } from 'vitest';

describe('邮箱验证集成测试', () => {
  const API_URL = 'https://api.emailverify.ai/v1/verify';
  let apiKey: string;

  beforeAll(() => {
    apiKey = process.env.EMAILVERIFY_API_KEY!;
    if (!apiKey) {
      throw new Error('未设置 EMAILVERIFY_API_KEY');
    }
  });

  async function verifyEmail(email: string) {
    const response = await fetch(API_URL, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${apiKey}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ email }),
    });
    return response.json();
  }

  it('对已知有效邮箱返回 valid', async () => {
    const result = await verifyEmail('test@gmail.com');
    expect(result.status).toBe('valid');
    expect(result.score).toBeGreaterThan(0.5);
  });

  it('检测一次性邮箱', async () => {
    const result = await verifyEmail('test@mailinator.com');
    expect(result.result.disposable).toBe(true);
  });

  it('检测角色邮箱', async () => {
    const result = await verifyEmail('info@example.com');
    expect(result.result.role).toBe(true);
  });

  it('处理无效域名', async () => {
    const result = await verifyEmail('user@thisisnotarealdomain12345.xyz');
    expect(result.status).toBe('invalid');
  });

  it('返回正确的结构', async () => {
    const result = await verifyEmail('user@example.com');

    expect(result).toHaveProperty('email');
    expect(result).toHaveProperty('status');
    expect(result).toHaveProperty('score');
    expect(result).toHaveProperty('result');
    expect(result.result).toHaveProperty('deliverable');
    expect(result.result).toHaveProperty('disposable');
    expect(result.result).toHaveProperty('role');
  });
});

Droid 别名

将这些添加到您的 Droid 配置:

# ~/.droid/aliases.yml
aliases:
  vmail:
    description: "验证邮箱地址"
    command: "bv verify $1 --color"

  vmail-json:
    description: "验证邮箱并输出 JSON"
    command: "bv verify $1 --json | jq ."

  vmail-batch:
    description: "从文件验证邮箱"
    command: "bv verify --file $1 --output results.csv"

  vmail-check:
    description: "快速检查邮箱是否有效(返回 0 或 1)"
    command: "bv verify $1 --quiet"

使用方法:

droid vmail user@example.com
droid vmail-batch contacts.txt

下一步

On this page