Skip to main content
Glama
mundume
by mundume

sendEmail

Send emails directly from Gmail by specifying recipient, subject, and body content for communication and note management.

Instructions

Send an email from Gmail.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesRecipient email address.
subjectYesEmail subject.
bodyYesEmail body.

Implementation Reference

  • The main handler function for sendEmail that validates input, constructs a raw email message, encodes it in base64 URL-safe format, and sends it via Gmail API
    case "sendEmail": { if (!GMAIL_API_KEY) { return { content: [{ type: "text", text: "API Key not set." }] }; } try { const { to, subject, body } = SendEmailSchema.parse( request.params.arguments ); let emailHeaders = `To: ${to}\r\nSubject: ${subject}\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n`; const raw = Buffer.from(emailHeaders + body) .toString("base64") .replace(/\+/g, "-") .replace(/\//g, "_") .replace(/=+$/, ""); console.log("Raw message:", raw); const response = await fetch( `https://gmail.googleapis.com/gmail/v1/users/${GMAIL_USER_ID}/messages/send`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${GMAIL_API_KEY}`, }, body: JSON.stringify({ raw: raw }), } ); if (!response.ok) { const errorData = await response.json(); console.error("Gmail API Error:", errorData); // Debugging: Log the full error const errorMessage = errorData.error?.message || response.statusText; return { content: [{ type: "text", text: `Error: ${errorMessage}` }], }; } return { content: [{ type: "text", text: "Email sent successfully." }], }; } catch (error: any) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } }
  • Zod schema definition for sendEmail tool input validation, defining required fields: to (email), subject (string), and body (string)
    const SendEmailSchema = z.object({ to: z.string().email().describe("Recipient email address."), subject: z.string().describe("Email subject."), body: z.string().describe("Email body."), });
  • src/index.ts:70-74 (registration)
    Tool registration in the MCP server's ListToolsRequestSchema handler, exposing sendEmail with its description and input schema
    { name: "sendEmail", description: "Send an email from Gmail.", inputSchema: zodToJsonSchema(SendEmailSchema), },
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/mundume/gmail-mcp'

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