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
| Name | Required | Description | Default |
|---|---|---|---|
| messagename | No | Email template name | |
| id | No | Related ID (client, invoice, etc.) | |
| customtype | No | Custom type | |
| customsubject | No | Custom subject | |
| custommessage | No | Custom 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) }], }; } );
- src/index.ts:1107-1113 (schema)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'), },
- src/whmcs-client.ts:1282-1291 (handler)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); }
- src/whmcs-client.ts:29-63 (helper)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; }