Skip to main content
Glama

whmcs_send_email

Send automated or custom emails to WHMCS clients using templates for invoices, notifications, and communications.

Instructions

Send an email to a client

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messagenameNoEmail template name
idNoRelated ID (client, invoice, etc.)
customtypeNoCustom type
customsubjectNoCustom subject
custommessageNoCustom message

Implementation Reference

  • src/index.ts:1103-1121 (registration)
    Registration of the 'whmcs_send_email' tool, including title, description, input schema using Zod, and the handler function that delegates to whmcsClient.sendEmail and formats the response.
        'whmcs_send_email',
        {
            title: 'Send Email',
            description: 'Send an email to a client',
            inputSchema: {
                messagename: z.string().optional().describe('Email template name'),
                id: z.number().optional().describe('Related ID (client, invoice, etc.)'),
                customtype: z.string().optional().describe('Custom type'),
                customsubject: z.string().optional().describe('Custom subject'),
                custommessage: z.string().optional().describe('Custom message'),
            },
        },
        async (params) => {
            const result = await whmcsClient.sendEmail(params);
            return {
                content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
            };
        }
    );
  • Input schema definition for the whmcs_send_email tool using Zod validators for parameters like messagename, id, customtype, etc.
    inputSchema: {
        messagename: z.string().optional().describe('Email template name'),
        id: z.number().optional().describe('Related ID (client, invoice, etc.)'),
        customtype: z.string().optional().describe('Custom type'),
        customsubject: z.string().optional().describe('Custom subject'),
        custommessage: z.string().optional().describe('Custom message'),
    },
  • Core handler implementation in WhmcsApiClient.sendEmail method, which makes the API call to WHMCS 'SendEmail' action with the provided parameters using the generic call method.
    async sendEmail(params: {
        messagename?: string;
        id?: number;
        customtype?: string;
        customsubject?: string;
        custommessage?: string;
        customvars?: string;
    }) {
        return this.call<WhmcsApiResponse>('SendEmail', params);
    }
  • Generic call method in WhmcsApiClient that handles all WHMCS API requests, including authentication, flattening params, POST request, and error handling. Used by sendEmail.
    async call<T extends WhmcsApiResponse>(action: string, params: Record<string, unknown> = {}): Promise<T> {
        const url = `${this.config.apiUrl.replace(/\/$/, '')}/includes/api.php`;
        
        const postData: Record<string, string> = {
            identifier: this.config.apiIdentifier,
            secret: this.config.apiSecret,
            action: action,
            responsetype: 'json',
            ...this.flattenParams(params)
        };
    
        if (this.config.accessKey) {
            postData.accesskey = this.config.accessKey;
        }
    
        const response = await fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: new URLSearchParams(postData).toString(),
        });
    
        if (!response.ok) {
            throw new Error(`WHMCS API request failed: ${response.status} ${response.statusText}`);
        }
    
        const data = await response.json() as T;
        
        if (data.result === 'error') {
            throw new Error(`WHMCS API error: ${data.message || 'Unknown error'}`);
        }
    
        return data;
    }

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/scarecr0w12/whmcs-mcp-server'

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