unsubscribeContact
Remove a contact from Mailmodo by unsubscribing or suppressing their email address to stop future communications.
Instructions
Unsubscribe or supress contact in mailmodo
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes |
Implementation Reference
- Core handler function that calls the Mailmodo API (POST /api/v1/contacts/unsubscribe) to unsubscribe a contact by email. Validates email input, sends the request with mmApiKey header, and returns success/failure 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'); } } - src/server.ts:243-273 (registration)Registers the 'unsubscribeContact' MCP tool on the server with a Zod schema requiring email (string). The handler delegates to the unsubscribeContact API function and formats the response.
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 }; } } ); - src/types/addContactsTypes.ts:77-81 (schema)Response type interface used by the unsubscribeContact function, containing success flag and optional message.
export interface AddContactToListResponse { // Define your expected response structure here success: boolean; message?: string; } - src/server.ts:6-6 (helper)Import statement that brings the unsubscribeContact function into the server module.
import { addContactToList, bulkAddContactToList, deleteContact, getAllContactLists, getContactDetails, removeContactFromList, resubscribeContact, unsubscribeContact } from "./apicalls/contactManagement";