Skip to main content
Glama
DynamicEndpoints

Advanced PocketBase MCP Server

send_templated_email

Send personalized emails using pre-designed templates. Integrates with PocketBase databases to streamline email campaigns and improve user communication efficiency.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function sendTemplatedEmail in EmailService class that fetches template from DB, compiles with Handlebars using variables, sends via nodemailer (SMTP or SendGrid), and logs result to PocketBase email_logs collection.
    async sendTemplatedEmail(data: { template: string; to: string; from?: string; variables?: Record<string, any>; customSubject?: string; }): Promise<EmailLog> { try { // Get template const template = await this.getTemplate(data.template); // Compile templates const subjectTemplate = Handlebars.compile(data.customSubject || template.subject); const htmlTemplate = Handlebars.compile(template.htmlContent); const textTemplate = template.textContent ? Handlebars.compile(template.textContent) : null; // Apply variables const variables = data.variables || {}; const subject = subjectTemplate(variables); const html = htmlTemplate(variables); const text = textTemplate ? textTemplate(variables) : undefined; // Send email const info = await this.transporter.sendMail({ from: data.from || process.env.SMTP_USER || process.env.DEFAULT_FROM_EMAIL, to: data.to, subject, html, text, }); // Log email const emailLog = await this.pb.collection('email_logs').create({ to: data.to, from: data.from || process.env.SMTP_USER || process.env.DEFAULT_FROM_EMAIL, subject, template: data.template, status: 'sent', variables: variables, }); return emailLog as unknown as EmailLog; } catch (error: any) { // Log failed email const emailLog = await this.pb.collection('email_logs').create({ to: data.to, from: data.from || process.env.SMTP_USER || process.env.DEFAULT_FROM_EMAIL, subject: data.customSubject || 'Email send failed', template: data.template, status: 'failed', error: error.message, variables: data.variables || {}, }); throw new Error(`Failed to send email: ${error.message}`); } }
  • MCP server tool registration for send_templated_email, including Zod input schema validation and handler that lazily initializes EmailService and delegates to its sendTemplatedEmail method.
    'send_templated_email', { description: 'Send a templated email using the configured email service', inputSchema: { template: z.string().describe('Email template name'), to: z.string().email().describe('Recipient email address'), from: z.string().email().optional().describe('Sender email address'), subject: z.string().optional().describe('Custom email subject'), variables: z.record(z.unknown()).optional().describe('Template variables') } }, async ({ template, to, from, subject, variables }) => { // Lazy load Email service await this.ensureEmailService(); if (!this.emailService) { throw new Error('Email service not available. Please configure EMAIL_SERVICE or SMTP settings.'); } try { const result = await this.emailService.sendTemplatedEmail({ template, to, from, customSubject: subject, variables }); return { content: [{ type: 'text', text: JSON.stringify({ success: true, emailLog: { id: result.id, to: result.to, subject: result.subject, status: result.status, sentAt: result.created } }, null, 2) }] }; } catch (error: any) { throw new Error(`Failed to send email: ${error.message}`); } } );
  • TypeScript type definition / schema for the sendTemplatedEmail input parameters.
    async sendTemplatedEmail(data: { template: string; to: string; from?: string; variables?: Record<string, any>; customSubject?: string; }): Promise<EmailLog> {
  • src/worker.ts:314-327 (registration)
    Tool listing / registration schema in Cloudflare Worker entry point for send_templated_email.
    name: 'send_templated_email', description: 'Send a templated email using the configured email service', inputSchema: { type: 'object', properties: { template: { type: 'string', description: 'Email template name' }, to: { type: 'string', format: 'email', description: 'Recipient email address' }, from: { type: 'string', format: 'email', description: 'Sender email address' }, subject: { type: 'string', description: 'Custom email subject' }, variables: { type: 'object', description: 'Template variables' } }, required: ['template', 'to'] } },

Other Tools

Related 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/DynamicEndpoints/advanced-pocketbase-mcp-server'

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