Skip to main content
Glama
TimeCyber

Email MCP Server

by TimeCyber

send_email

Send emails with attachments to multiple recipients using the Email MCP Server. Specify recipients, subject, content, and optional CC/BCC fields.

Instructions

发送邮件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYes收件人邮箱地址列表
ccNo抄送邮箱地址列表(可选)
bccNo密送邮箱地址列表(可选)
subjectYes邮件主题
textYes纯文本邮件内容
htmlNoHTML格式邮件内容(可选)
attachmentsNo邮件附件列表(可选)

Implementation Reference

  • The core handler function for the 'send_email' tool. It destructures input arguments, creates an SMTP transporter using createSMTPTransporter helper, prepares mail options including handling attachments, sends the email via nodemailer, and returns a success message with details.
    async sendEmail(args) {
      const { to, cc, bcc, subject, text, html, attachments } = args;
    
      const transporter = this.createSMTPTransporter();
    
      const mailOptions = {
        from: process.env.EMAIL_USER || process.env.WECHAT_EMAIL_USER,
        to: Array.isArray(to) ? to.join(', ') : to,
        cc: cc ? (Array.isArray(cc) ? cc.join(', ') : cc) : undefined,
        bcc: bcc ? (Array.isArray(bcc) ? bcc.join(', ') : bcc) : undefined,
        subject,
        text,
        html
      };
    
      // 处理附件
      if (attachments && attachments.length > 0) {
        mailOptions.attachments = attachments.map(att => {
          if (att.content) {
            return {
              filename: att.filename,
              content: att.content,
              encoding: 'base64'
            };
          } else if (att.path) {
            return {
              filename: att.filename,
              path: att.path
            };
          }
          return att;
        });
      }
    
      const result = await transporter.sendMail(mailOptions);
    
      return {
        content: [
          {
            type: 'text',
            text: `邮件发送成功!\n消息ID: ${result.messageId}\n收件人: ${Array.isArray(to) ? to.join(', ') : to}\n主题: ${subject}`
          }
        ]
      };
    }
  • Input schema definition for the 'send_email' tool, specifying parameters like to, cc, bcc, subject, text, html, attachments, with required fields to, subject, text.
    inputSchema: {
      type: 'object',
      properties: {
        to: {
          type: 'array',
          items: { type: 'string' },
          description: '收件人邮箱地址列表'
        },
        cc: {
          type: 'array',
          items: { type: 'string' },
          description: '抄送邮箱地址列表(可选)'
        },
        bcc: {
          type: 'array',
          items: { type: 'string' },
          description: '密送邮箱地址列表(可选)'
        },
        subject: {
          type: 'string',
          description: '邮件主题'
        },
        text: {
          type: 'string',
          description: '纯文本邮件内容'
        },
        html: {
          type: 'string',
          description: 'HTML格式邮件内容(可选)'
        },
        attachments: {
          type: 'array',
          items: {
            type: 'object',
            properties: {
              filename: { type: 'string', description: '附件文件名' },
              path: { type: 'string', description: '附件文件路径' },
              content: { type: 'string', description: '附件内容(base64编码)' }
            }
          },
          description: '邮件附件列表(可选)'
        }
      },
      required: ['to', 'subject', 'text']
    }
  • index.js:166-214 (registration)
    Registration of the 'send_email' tool in the ListToolsRequestSchema handler response, including name, description, and inputSchema.
    {
      name: 'send_email',
      description: '发送邮件',
      inputSchema: {
        type: 'object',
        properties: {
          to: {
            type: 'array',
            items: { type: 'string' },
            description: '收件人邮箱地址列表'
          },
          cc: {
            type: 'array',
            items: { type: 'string' },
            description: '抄送邮箱地址列表(可选)'
          },
          bcc: {
            type: 'array',
            items: { type: 'string' },
            description: '密送邮箱地址列表(可选)'
          },
          subject: {
            type: 'string',
            description: '邮件主题'
          },
          text: {
            type: 'string',
            description: '纯文本邮件内容'
          },
          html: {
            type: 'string',
            description: 'HTML格式邮件内容(可选)'
          },
          attachments: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                filename: { type: 'string', description: '附件文件名' },
                path: { type: 'string', description: '附件文件路径' },
                content: { type: 'string', description: '附件内容(base64编码)' }
              }
            },
            description: '邮件附件列表(可选)'
          }
        },
        required: ['to', 'subject', 'text']
      }
    },
  • index.js:346-347 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement that routes 'send_email' calls to the sendEmail handler method.
    case 'send_email':
      return await this.sendEmail(args);
  • Helper method to create the nodemailer SMTP transporter, handling auto-configuration based on email provider detection from environment variables.
    createSMTPTransporter() {
      try {
        // 如果已经有手动配置的设置,直接使用
        if (process.env.EMAIL_SMTP_HOST || process.env.WECHAT_EMAIL_HOST) {
          const config = {
            host: process.env.EMAIL_SMTP_HOST || process.env.WECHAT_EMAIL_HOST,
            port: parseInt(process.env.EMAIL_SMTP_PORT || process.env.WECHAT_EMAIL_PORT) || 587,
            secure: (process.env.EMAIL_SMTP_SECURE || process.env.WECHAT_EMAIL_SECURE) !== 'false',
            auth: {
              user: process.env.EMAIL_USER || process.env.WECHAT_EMAIL_USER,
              pass: process.env.EMAIL_PASSWORD || process.env.WECHAT_EMAIL_PASSWORD
            },
            connectionTimeout: 30000,
            greetingTimeout: 30000,
            socketTimeout: 30000
          };
          console.log('使用手动配置的SMTP设置:', { host: config.host, port: config.port, secure: config.secure });
          return nodemailer.createTransport(config);
        }
    
        // 自动配置
        const emailUser = process.env.EMAIL_USER || process.env.WECHAT_EMAIL_USER;
        const emailType = process.env.EMAIL_TYPE; // 手动指定的邮箱类型
        
        if (!emailUser) {
          throw new Error('缺少邮箱用户名配置。请设置 EMAIL_USER 环境变量。');
        }
    
        const provider = this.detectEmailProvider(emailUser, emailType);
        if (!provider) {
          throw new Error(`无法识别邮箱类型: ${emailUser}。如果是企业邮箱,请设置 EMAIL_TYPE 环境变量(如: 'exmail' 代表腾讯企业邮箱)`);
        }
    
        const emailConfig = EMAIL_CONFIGS[provider];
        const config = {
          host: emailConfig.smtp.host,
          port: emailConfig.smtp.port,
          secure: emailConfig.smtp.secure,
          auth: {
            user: emailUser,
            pass: process.env.EMAIL_PASSWORD || process.env.WECHAT_EMAIL_PASSWORD
          },
          connectionTimeout: 30000,
          greetingTimeout: 30000,
          socketTimeout: 30000
        };
    
        // 验证必需的配置项
        if (!config.auth.pass) {
          throw new Error('缺少邮箱密码配置。请设置 EMAIL_PASSWORD 环境变量。');
        }
    
        console.log(`自动配置SMTP设置 - 邮箱类型: ${emailConfig.name}`, { host: config.host, port: config.port, secure: config.secure });
        return nodemailer.createTransport(config);
      } catch (error) {
        console.error('创建SMTP传输器失败:', error.message);
        throw error;
      }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TimeCyber/email-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server