unsubscribeContact
Remove or suppress a contact from Mailmodo’s email campaigns by specifying their email address, ensuring compliance with unsubscribe requests.
Instructions
Unsubscribe or supress contact in mailmodo
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes |
Implementation Reference
- src/server.ts:243-272 (registration)Registration of the MCP tool 'unsubscribeContact' including inline input schema (email: z.string()) and handler wrapper that invokes the core unsubscribeContact function.server.tool( "unsubscribeContact", "Unsubscribe or supress contact in mailmodo", { email: z.string() }, async (params) => { try { const respone = await unsubscribeContact(mmApiKey,params.email); // Here you would typically integrate with your event sending system // For example: eventBus.emit(eventName, eventData) // For demonstration, we'll just return a success message return { content: [{ type: "text", text: respone.success ?`Successfully unsubscribed '${params.email} with message ${respone.message}.`: `Something went wrong. Please check if the email is correct`, }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : "Failed to unsubscribe", }], isError: true }; } }
- Core handler function that performs the HTTP POST request to Mailmodo's unsubscribe endpoint, handling errors and returning the response.export async function unsubscribeContact( mmApiKey: string, email: string ): Promise<AddContactToListResponse> { if (!email) { throw new Error('Email is a required field'); } try { const response = await axios.post<AddContactToListResponse>( 'https://api.mailmodo.com/api/v1/contacts/unsubscribe', { email, }, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'mmApiKey': mmApiKey || '' } } ); return response.data; } catch (error) { if (error instanceof AxiosError) { return { success: false, message: error.response?.data?.message || 'Failed to unsubscribe contact' }; } throw new Error('An unexpected error occurred'); } }