liara_create_mail_server
Create a new mail server on Liara cloud platform by specifying domain, plan, and mode for email hosting setup.
Instructions
Create a new mail server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Mail server name | |
| mode | No | Mail server mode | |
| planID | Yes | Plan ID for the mail server (required) | |
| domain | Yes | Domain name for the mail server (required) |
Implementation Reference
- src/services/mail.ts:58-86 (handler)The core handler function that implements the logic to create a new mail server on Liara by posting to the mail service API endpoint with validated parameters (domain required, planID required, mode defaults to DEV). Returns the created MailServer object.* Create a new mail server */ export async function createMailServer( client: LiaraClient, _name: string, mode?: 'DEV' | 'LIVE', planID?: string, domain?: string ): Promise<MailServer> { // Note: '_name' parameter is kept for backward compatibility but not sent to API validateRequired(planID, 'Plan ID'); validateRequired(domain, 'Domain'); const requestBody: { mode?: 'DEV' | 'LIVE'; plan?: string; planID?: string; domain?: string } = { domain: domain!, }; if (mode) { requestBody.mode = mode; } else { // Default to 'DEV' if mode is not provided requestBody.mode = 'DEV'; } if (planID) { requestBody.plan = planID; requestBody.planID = planID; } const mailClient = createMailClient(client); const response = await mailClient.post<any>('/v1/mails', requestBody); return unwrapApiResponse<MailServer>(response, ['mail', 'mailServer', 'data']); }
- src/api/types.ts:287-293 (schema)TypeScript interface defining the structure of a MailServer object, which is the output type of the createMailServer function.export interface MailServer { _id: string; name: string; mode: 'DEV' | 'LIVE'; status: 'ACTIVE' | 'INACTIVE'; createdAt: string; }
- src/services/mail.ts:13-30 (helper)Helper function that creates a specialized LiaraClient for the Mail service API with the correct baseURL and inherited authentication.function createMailClient(client: LiaraClient): LiaraClient { // Access the internal client to get the API token const internalClient = (client as any).client; const apiToken = internalClient?.defaults?.headers?.Authorization?.replace('Bearer ', '') || process.env.LIARA_API_TOKEN; const teamId = (client as any).teamId || process.env.LIARA_TEAM_ID; if (!apiToken) { throw new Error('API token is required for Mail operations'); } // Create new client with Mail service base URL return new LiaraClient({ apiToken, teamId, baseURL: 'https://mail-service.liara.ir/api', }); }