Skip to main content
Glama

send_email

Send emails through Gmail SMTP by providing recipient address, subject line, and message body content.

Instructions

Send an email using Gmail SMTP

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYesRecipient email address
subjectYesEmail subject
bodyYesEmail body content

Implementation Reference

  • MCP tool handler for 'send_email' that invokes the internal sendEmail function and returns formatted content with structured result.
    async ({ to, subject, body }) => { const result = await sendEmail(to, subject, body); return { content: [{ type: 'text', text: result.success ? `Email sent to ${to}. Message ID: ${result.messageId}` : `Failed to send email: ${result.error}` }], structuredContent: result }; }
  • Input schema (to, subject, body with Zod validation) and output schema (success, messageId, error) for the send_email tool.
    inputSchema: { to: z.string().email().describe('Recipient email address'), subject: z.string().min(1).describe('Email subject'), body: z.string().min(1).describe('Email body content') }, outputSchema: { success: z.boolean().describe('Whether email was sent successfully'), messageId: z.string().optional().describe('Message ID from Gmail'), error: z.string().optional().describe('Error message if failed') }
  • src/index.ts:54-83 (registration)
    Registration of the 'send_email' tool on the MCP server with schema and handler.
    server.registerTool( 'send_email', { title: 'Send Email', description: 'Send an email using Gmail SMTP', inputSchema: { to: z.string().email().describe('Recipient email address'), subject: z.string().min(1).describe('Email subject'), body: z.string().min(1).describe('Email body content') }, outputSchema: { success: z.boolean().describe('Whether email was sent successfully'), messageId: z.string().optional().describe('Message ID from Gmail'), error: z.string().optional().describe('Error message if failed') } }, async ({ to, subject, body }) => { const result = await sendEmail(to, subject, body); return { content: [{ type: 'text', text: result.success ? `Email sent to ${to}. Message ID: ${result.messageId}` : `Failed to send email: ${result.error}` }], structuredContent: result }; } );
  • Internal helper function that performs the actual email sending using nodemailer and Gmail transporter.
    async function sendEmail(to: string, subject: string, body: string) { const transporter = createEmailTransporter(); try { const info = await transporter.sendMail({ from: process.env.GMAIL_USER, to, subject, text: body, }); return { success: true, messageId: info.messageId, }; } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Unknown error', }; } }
  • Helper function to create and configure the nodemailer transporter for Gmail SMTP using environment variables.
    function createEmailTransporter() { const user = process.env.GMAIL_USER; const pass = process.env.GMAIL_PASS; if (!user || !pass) { throw new Error('Gmail credentials not found. Set GMAIL_USER and GMAIL_PASS environment variables.'); } return nodemailer.createTransport({ service: 'gmail', auth: { user, pass }, }); }

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/PranavMishra28/gmail-mcp'

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