setup_email_account
Configure email accounts by automatically detecting provider settings or specifying them manually for integration with email services.
Instructions
设置邮箱账号(自动识别邮箱类型并配置服务器)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes | 邮箱地址(如 user@qq.com) | ||
| password | Yes | 邮箱密码或授权码 | |
| provider | No | 邮箱提供商(可选,不填写则自动识别) |
Implementation Reference
- index.js:959-1015 (handler)The main handler function that executes the setup_email_account tool. It sets EMAIL_USER and EMAIL_PASSWORD environment variables, detects the email provider if not specified, auto-configures server settings using EMAIL_CONFIGS, and returns a success message with configuration details or an error.async setupEmailAccount(args) { const { email, password, provider } = args; // 设置用户名和密码 process.env.EMAIL_USER = email; process.env.EMAIL_PASSWORD = password; let detectedProvider = provider; let config; try { // 如果没有指定提供商,则自动检测 if (!detectedProvider) { detectedProvider = this.detectEmailProvider(email); if (!detectedProvider) { return { content: [{ type: 'text', text: `❌ 无法识别邮箱类型: ${email}\n\n支持的邮箱类型请使用 list_supported_providers 查看,或手动指定 provider 参数。` }] }; } } // 自动配置服务器设置 config = this.autoConfigureByProvider(detectedProvider); let result = `✅ 邮箱账号设置成功!\n\n`; result += `📧 邮箱地址: ${email}\n`; result += `🏢 邮箱提供商: ${config.name}\n`; result += `📤 SMTP服务器: ${config.smtp.host}:${config.smtp.port} (SSL: ${config.smtp.secure})\n`; result += `📥 接收协议: ${config.usePOP3 ? 'POP3' : 'IMAP'}\n`; if (config.usePOP3) { result += `📥 POP3服务器: ${config.pop3.host}:${config.pop3.port} (SSL: ${config.pop3.secure})\n`; } else { result += `📥 IMAP服务器: ${config.imap.host}:${config.imap.port} (SSL: ${config.imap.secure})\n`; } result += `\n💡 提示: 配置已自动完成,您现在可以使用邮件功能了!`; return { content: [{ type: 'text', text: result }] }; } catch (error) { return { content: [{ type: 'text', text: `❌ 邮箱设置失败: ${error.message}` }] }; } }
- index.js:247-269 (registration)Registers the 'setup_email_account' tool in the MCP server's listTools response, including name, description, and input schema definition.{ name: 'setup_email_account', description: '设置邮箱账号(自动识别邮箱类型并配置服务器)', inputSchema: { type: 'object', properties: { email: { type: 'string', description: '邮箱地址(如 user@qq.com)' }, password: { type: 'string', description: '邮箱密码或授权码' }, provider: { type: 'string', enum: ['qq', '163', 'gmail', 'outlook', 'exmail', 'aliyun', 'sina', 'sohu'], // 暂时注释掉: 'netease-enterprise' description: '邮箱提供商(可选,不填写则自动识别)' } }, required: ['email', 'password'] } },
- index.js:352-353 (registration)In the CallToolRequestSchema handler, dispatches calls to 'setup_email_account' to the setupEmailAccount method.case 'setup_email_account': return await this.setupEmailAccount(args);
- index.js:111-131 (helper)Helper method to detect email provider from email domain or manual type, used by setupEmailAccount.detectEmailProvider(email, manualType = null) { // 优先使用手动指定的邮箱类型 if (manualType && EMAIL_CONFIGS[manualType]) { console.log(`使用手动指定的邮箱类型: ${manualType} (${EMAIL_CONFIGS[manualType].name})`); return manualType; } // 如果没有手动指定,则根据域名自动检测 const domain = email.split('@')[1]?.toLowerCase(); if (!domain) return null; for (const [provider, config] of Object.entries(EMAIL_CONFIGS)) { if (config.domains.includes(domain)) { console.log(`自动检测到邮箱类型: ${provider} (${config.name})`); return provider; } } console.log(`未能识别邮箱类型,域名: ${domain}`); return null; }
- index.js:134-159 (helper)Helper method that sets environment variables for email servers based on the detected provider, used by setupEmailAccount.autoConfigureByProvider(provider) { const config = EMAIL_CONFIGS[provider]; if (!config) { throw new Error(`不支持的邮箱类型: ${provider}`); } // 设置SMTP配置 process.env.EMAIL_SMTP_HOST = config.smtp.host; process.env.EMAIL_SMTP_PORT = config.smtp.port.toString(); process.env.EMAIL_SMTP_SECURE = config.smtp.secure.toString(); // 设置IMAP配置 process.env.EMAIL_IMAP_HOST = config.imap.host; process.env.EMAIL_IMAP_PORT = config.imap.port.toString(); process.env.EMAIL_IMAP_SECURE = config.imap.secure.toString(); // 设置POP3配置 process.env.EMAIL_POP3_HOST = config.pop3.host; process.env.EMAIL_POP3_PORT = config.pop3.port.toString(); process.env.EMAIL_POP3_SECURE = config.pop3.secure.toString(); // 设置协议偏好 process.env.EMAIL_USE_POP3 = config.usePOP3.toString(); return config; }