Skip to main content
Glama
MadLlama25

Fastmail MCP Server

by MadLlama25

send_email

Send email messages with customizable recipients, subject, and body in plain text or HTML, including CC, BCC, and reply threading support.

Instructions

Send an email

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesRecipient email addresses (array of strings, or a comma-separated string)
ccNoCC email addresses (optional)
bccNoBCC email addresses (optional)
fromNoSender email address (optional, defaults to account primary email)
mailboxIdNoMailbox ID to save the email to (optional, defaults to Drafts folder)
subjectYesEmail subject
textBodyNoPlain text body (optional)
htmlBodyNoHTML body (optional)
inReplyToNoMessage-ID(s) of the email being replied to (optional, for threading)
referencesNoFull reference chain of Message-IDs (optional, for threading)
replyToNoReply-To email addresses (replies go here instead of to the sender)

Implementation Reference

  • src/index.ts:178-239 (registration)
    Tool registration for 'send_email' in the ListToolsRequestSchema handler, including input schema (to, cc, bcc, from, mailboxId, subject, textBody, htmlBody, inReplyTo, references, replyTo).
    {
      name: 'send_email',
      description: 'Send an email',
      inputSchema: {
        type: 'object',
        properties: {
          to: {
            oneOf: [
              { type: 'array', items: { type: 'string' } },
              { type: 'string' },
            ],
            description: 'Recipient email addresses (array of strings, or a comma-separated string)',
          },
          cc: {
            type: 'array',
            items: { type: 'string' },
            description: 'CC email addresses (optional)',
          },
          bcc: {
            type: 'array',
            items: { type: 'string' },
            description: 'BCC email addresses (optional)',
          },
          from: {
            type: 'string',
            description: 'Sender email address (optional, defaults to account primary email)',
          },
          mailboxId: {
            type: 'string',
            description: 'Mailbox ID to save the email to (optional, defaults to Drafts folder)',
          },
          subject: {
            type: 'string',
            description: 'Email subject',
          },
          textBody: {
            type: 'string',
            description: 'Plain text body (optional)',
          },
          htmlBody: {
            type: 'string',
            description: 'HTML body (optional)',
          },
          inReplyTo: {
            type: 'array',
            items: { type: 'string' },
            description: 'Message-ID(s) of the email being replied to (optional, for threading)',
          },
          references: {
            type: 'array',
            items: { type: 'string' },
            description: 'Full reference chain of Message-IDs (optional, for threading)',
          },
          replyTo: {
            type: 'array',
            items: { type: 'string' },
            description: 'Reply-To email addresses (replies go here instead of to the sender)',
          },
        },
        required: ['to', 'subject'],
      },
    },
  • Handler for 'send_email' in the CallToolRequestSchema switch statement. Validates arguments (to, subject, textBody/htmlBody), coerces 'to' to an array, then calls client.sendEmail().
    case 'send_email': {
      const { to, cc, bcc, from, mailboxId, subject, textBody, htmlBody, inReplyTo, references, replyTo } = args as any;
      const toArray = coerceStringArray(to);
      if (!toArray || toArray.length === 0) {
        throw new McpError(ErrorCode.InvalidParams, 'to field is required and must be a non-empty array');
      }
      if (!subject) {
        throw new McpError(ErrorCode.InvalidParams, 'subject is required');
      }
      if (!textBody && !htmlBody) {
        throw new McpError(ErrorCode.InvalidParams, 'Either textBody or htmlBody is required');
      }
    
      const submissionId = await client.sendEmail({
        to: toArray,
        cc,
        bcc,
        from,
        mailboxId,
        subject,
        textBody,
        htmlBody,
        inReplyTo,
        references,
        replyTo,
      });
    
      return {
        content: [
          {
            type: 'text',
            text: `Email sent successfully. Submission ID: ${submissionId}`,
          },
        ],
      };
    }
  • The core sendEmail() method on JmapClient that builds the JMAP Email/set and EmailSubmission/set requests to create and submit the email via the JMAP API.
    async sendEmail(email: {
      to: string[];
      cc?: string[];
      bcc?: string[];
      subject: string;
      textBody?: string;
      htmlBody?: string;
      from?: string;
      mailboxId?: string;
      inReplyTo?: string[];
      references?: string[];
      replyTo?: string[];
    }): Promise<string> {
      const session = await this.getSession();
    
      // Get all identities to validate from address
      const identities = await this.getIdentities();
      if (!identities || identities.length === 0) {
        throw new Error('No sending identities found');
      }
    
      // Determine which identity to use
      let selectedIdentity;
      if (email.from) {
        // Validate that the from address matches an available identity
        selectedIdentity = identities.find(id => matchesIdentity(id.email, email.from!));
        if (!selectedIdentity) {
          throw new Error('From address is not verified for sending. Choose one of your verified identities.');
        }
      } else {
        // Use default identity
        selectedIdentity = identities.find(id => id.mayDelete === false) || identities[0];
      }
    
      // Use the requested from address (not the identity email, which may be a wildcard like *@domain)
      const fromEmail = email.from || selectedIdentity.email;
    
      // Get the mailbox IDs we need
      const mailboxes = await this.getMailboxes();
      const draftsMailbox = this.findMailboxByRoleOrName(mailboxes, 'drafts', 'draft');
      const sentMailbox = this.findMailboxByRoleOrName(mailboxes, 'sent', 'sent');
    
      if (!draftsMailbox) {
        throw new Error('Could not find Drafts mailbox to save email');
      }
      if (!sentMailbox) {
        throw new Error('Could not find Sent mailbox to move email after sending');
      }
    
      // Use provided mailboxId or default to drafts for initial creation
      const initialMailboxId = email.mailboxId || draftsMailbox.id;
    
      // Ensure we have at least one body type
      if (!email.textBody && !email.htmlBody) {
        throw new Error('Either textBody or htmlBody must be provided');
      }
    
      const initialMailboxIds: Record<string, boolean> = {};
      initialMailboxIds[initialMailboxId] = true;
    
      const sentMailboxIds: Record<string, boolean> = {};
      sentMailboxIds[sentMailbox.id] = true;
    
      const emailObject = {
        mailboxIds: initialMailboxIds,
        keywords: { $draft: true },
        from: [{ name: selectedIdentity.name, email: fromEmail }],
        to: email.to.map(addr => ({ email: addr })),
        cc: email.cc?.map(addr => ({ email: addr })) || [],
        bcc: email.bcc?.map(addr => ({ email: addr })) || [],
        subject: email.subject,
        ...(email.inReplyTo && { inReplyTo: email.inReplyTo }),
        ...(email.references && { references: email.references }),
        ...(email.replyTo?.length && { replyTo: email.replyTo.map(addr => ({ email: addr })) }),
        textBody: email.textBody ? [{ partId: 'text', type: 'text/plain' }] : undefined,
        htmlBody: email.htmlBody ? [{ partId: 'html', type: 'text/html' }] : undefined,
        bodyValues: {
          ...(email.textBody && { text: { value: email.textBody } }),
          ...(email.htmlBody && { html: { value: email.htmlBody } })
        }
      };
    
      const request: JmapRequest = {
        using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail', 'urn:ietf:params:jmap:submission'],
        methodCalls: [
          ['Email/set', {
            accountId: session.accountId,
            create: { draft: emailObject }
          }, 'createEmail'],
          ['EmailSubmission/set', {
            accountId: session.accountId,
            create: {
              submission: {
                emailId: '#draft',
                identityId: selectedIdentity.id,
                envelope: {
                  mailFrom: { email: fromEmail },
                  rcptTo: [
                    ...email.to.map(addr => ({ email: addr })),
                    ...(email.cc || []).map(addr => ({ email: addr })),
                    ...(email.bcc || []).map(addr => ({ email: addr })),
                  ]
                }
              }
            },
            onSuccessUpdateEmail: {
              '#submission': {
                mailboxIds: sentMailboxIds,
                keywords: { $seen: true }
              }
            }
          }, 'submitEmail']
        ]
      };
    
      const response = await this.makeRequest(request);
    
      const emailResult = this.getMethodResult(response, 0);
      if (emailResult.notCreated?.draft) {
        const err = emailResult.notCreated.draft;
        throw new Error(`Failed to create email: ${err.type}${err.description ? ' - ' + err.description : ''}`);
      }
    
      const emailId = emailResult.created?.draft?.id;
      if (!emailId) {
        throw new Error('Email creation returned no email ID');
      }
    
      const submissionResult = this.getMethodResult(response, 1);
      if (submissionResult.notCreated?.submission) {
        const err = submissionResult.notCreated.submission;
        throw new Error(`Failed to submit email: ${err.type}${err.description ? ' - ' + err.description : ''}`);
      }
    
      const submissionId = submissionResult.created?.submission?.id;
      if (!submissionId) {
        throw new Error('Email submission returned no submission ID');
      }
    
      return submissionId;
    }
  • coerceStringArray helper used by the send_email handler to convert the 'to' parameter (which may be a string, comma-separated string, or array) into a string array.
    export function coerceStringArray(value: unknown): string[] | undefined {
      if (value === undefined || value === null) return undefined;
      if (Array.isArray(value)) return value.map(String);
      if (typeof value !== 'string') return undefined;
      const trimmed = value.trim();
      if (!trimmed) return [];
      if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
        try {
          const parsed = JSON.parse(trimmed);
          if (Array.isArray(parsed)) return parsed.map(String);
        } catch { /* fall through to comma-split */ }
      }
      return trimmed.split(',').map(s => s.trim()).filter(Boolean);
    }
Behavior2/5

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

With no annotations, the description must disclose behavioral traits. It merely states the action without explaining side effects (e.g., email is actually sent), auth requirements, or any constraints beyond schema.

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

Conciseness4/5

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

The description is extremely concise (three words), front-loading the core purpose. However, it lacks any additional structure or examples, which could be added without losing conciseness.

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?

Given 11 parameters and no output schema, the description should cover basic behavior (e.g., whether sent email is saved, threading support). It provides none of this context, leaving the agent underinformed.

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?

Schema coverage is 100%, so baseline is 3. The description adds no additional meaning; it just repeats the tool's purpose.

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

Purpose5/5

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

The description 'Send an email' uses a specific verb and resource clearly indicating the tool's action. It distinguishes itself from sibling tools like 'create_draft' and 'reply_email' which have different intents (drafting vs replying).

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?

No guidance on when to use this tool versus alternatives like 'create_draft' or 'reply_email'. The description lacks context about prerequisites or typical use cases.

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/MadLlama25/fastmail-mcp'

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