Skip to main content
Glama

send_email

Send emails with HTML formatting and attachments using the Mail MCP Server. Configure recipients, subject, and content to deliver messages.

Instructions

Send an email with optional HTML body and attachments

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesList of recipient email addresses
subjectYesEmail subject
body_textNoPlain text body
body_htmlNoHTML body
ccNoCC recipients
bccNoBCC recipients
attachmentsNoAttachments (base64 encoded)

Implementation Reference

  • The core logic for sending emails, including parameter validation, email construction, and actual SMTP transmission.
    def send_email(
        client,
        to: list[str],
        subject: str,
        body_text: str | None = None,
        body_html: str | None = None,
        cc: list[str] | None = None,
        bcc: list[str] | None = None,
        attachments: list[Attachment] | None = None,
        from_addr: str | None = None,
    ) -> SendResult:
        """
        发送邮件
    
        Args:
            client: SMTP 客户端对象
            to: 收件人列表 (必填)
            subject: 主题 (必填)
            body_text: 纯文本正文
            body_html: HTML 正文
            cc: 抄送列表
            bcc: 密送列表
            attachments: 附件列表
            from_addr: 发件人地址
    
        Returns:
            SendResult: 发送结果
        """
        # 1. 验证参数
        if not to:
            return SendResult(success=False, error="收件人列表不能为空")
    
        if not subject:
            return SendResult(success=False, error="邮件主题不能为空")
    
        if not body_text and not body_html:
            return SendResult(success=False, error="邮件正文不能为空")
    
        # 验证邮箱地址
        for addr in to:
            if not validate_email_address(addr):
                return SendResult(success=False, error=f"无效的收件人地址: {addr}")
    
        if cc:
            for addr in cc:
                if not validate_email_address(addr):
                    return SendResult(success=False, error=f"无效的抄送地址: {addr}")
    
        if bcc:
            for addr in bcc:
                if not validate_email_address(addr):
                    return SendResult(success=False, error=f"无效的密送地址: {addr}")
    
        try:
            # 获取发件人地址
            if not from_addr:
                if hasattr(client, "config") and hasattr(client.config, "user"):
                    from_addr = client.config.user
                else:
                    return SendResult(success=False, error="缺少发件人地址")
    
            # 2. 构建邮件消息
            message = build_email_message(
                sender=from_addr,
                to=to,
                subject=subject,
                body_text=body_text,
                body_html=body_html,
                cc=cc,
                bcc=bcc,
                attachments=attachments,
            )
    
            # 生成 Message-ID
            message_id = make_msgid()
            message["Message-ID"] = message_id
    
            # 3. 获取所有收件人
            all_recipients = to.copy()
            if cc:
                all_recipients.extend(cc)
            if bcc:
                all_recipients.extend(bcc)
    
            # 4. 发送邮件
            smtp = _get_smtp_client(client)
    
            # 确保连接已建立
            if smtp is None:
                # 尝试连接
                if hasattr(client, "connect"):
                    client.connect()
                    smtp = _get_smtp_client(client)
    
            if smtp is None:
                return SendResult(success=False, error="无法获取 SMTP 连接")
    
            smtp.send_message(message, from_addr=from_addr, to_addrs=all_recipients)
    
            return SendResult(success=True, message_id=message_id, rejected=None)
    
        except smtplib.SMTPAuthenticationError as e:
            return SendResult(success=False, error=f"认证失败: {str(e)}")
        except smtplib.SMTPSenderRefused as e:
            return SendResult(success=False, error=f"发件人被拒绝: {str(e)}")
        except smtplib.SMTPRecipientsRefused as e:
            rejected = list(e.recipients.keys())
            return SendResult(success=False, error=f"收件人被拒绝: {str(e)}", rejected=rejected)
        except smtplib.SMTPException as e:
            return SendResult(success=False, error=f"SMTP 错误: {str(e)}")
        except Exception as e:
            return SendResult(success=False, error=f"发送失败: {str(e)}")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only notes that HTML and attachments are 'optional' but fails to disclose mutation side effects, success/failure indicators, rate limits, or attachment size constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action. It contains no redundant or wasted words given the information it chooses to convey.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter mutation tool with no output schema and no annotations, the description is insufficient. It lacks critical context such as return values, error handling, authentication scope, or operational limits (e.g., attachment size) that an agent needs to invoke the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the schema already fully documents all 7 parameters. The description adds minimal semantic value beyond confirming that HTML body and attachments are optional features, meeting the baseline expectation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the specific action ('Send an email') and mentions key capabilities ('optional HTML body and attachments'). However, it does not explicitly differentiate from sibling tools like send_forward or send_reply, leaving the distinction to be inferred from tool names alone.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like send_reply or send_forward, nor does it mention prerequisites such as authentication requirements or rate limits.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/AdJIa/mail-mcp-server'

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