send_draft
Send an existing draft email from your Gmail account by providing the draft ID. This tool allows you to finalize and dispatch prepared email messages that were previously saved as drafts.
Instructions
Send an existing draft
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the draft to send |
Implementation Reference
- src/index.ts:343-352 (handler)The async handler function for the 'send_draft' tool. It calls the shared 'handleTool' utility to authenticate via OAuth2, create a Gmail client, and invoke the Gmail API to send the specified draft by ID. Includes error handling for common issues like missing recipients.async (params) => { return handleTool(config, async (gmail: gmail_v1.Gmail) => { try { const { data } = await gmail.users.drafts.send({ userId: 'me', requestBody: { id: params.id } }) return formatResponse(data) } catch (error) { return formatResponse({ error: 'Error sending draft, are you sure you have at least one recipient?' }) } }) }
- src/index.ts:340-342 (schema)Zod schema defining the input parameters for the 'send_draft' tool: a required string 'id' for the draft ID.{ id: z.string().describe("The ID of the draft to send") },
- src/index.ts:338-353 (registration)Registration of the 'send_draft' tool using server.tool(), including the tool name, description, input schema, and inline handler function.server.tool("send_draft", "Send an existing draft", { id: z.string().describe("The ID of the draft to send") }, async (params) => { return handleTool(config, async (gmail: gmail_v1.Gmail) => { try { const { data } = await gmail.users.drafts.send({ userId: 'me', requestBody: { id: params.id } }) return formatResponse(data) } catch (error) { return formatResponse({ error: 'Error sending draft, are you sure you have at least one recipient?' }) } }) } )
- src/index.ts:49-65 (helper)Shared helper function used by 'send_draft' (and other tools) to manage OAuth2 client creation, credential validation, Gmail API client instantiation, and execution of the tool-specific API call with error handling.const handleTool = async (queryConfig: Record<string, any> | undefined, apiCall: (gmail: gmail_v1.Gmail) => Promise<any>) => { try { const oauth2Client = queryConfig ? createOAuth2Client(queryConfig) : defaultOAuth2Client if (!oauth2Client) throw new Error('OAuth2 client could not be created, please check your credentials') const credentialsAreValid = await validateCredentials(oauth2Client) if (!credentialsAreValid) throw new Error('OAuth2 credentials are invalid, please re-authenticate') const gmailClient = queryConfig ? google.gmail({ version: 'v1', auth: oauth2Client }) : defaultGmailClient if (!gmailClient) throw new Error('Gmail client could not be created, please check your credentials') const result = await apiCall(gmailClient) return result } catch (error: any) { return `Tool execution failed: ${error.message}` } }