resubscribeContact
Re-add a previously unsubscribed contact to your Mailmodo mailing list by providing their email address. Restore communication with opted-out subscribers.
Instructions
Resubscribe contact in mailmodo
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes |
Implementation Reference
- The actual implementation of the resubscribeContact function. It takes mmApiKey and email, validates email is provided, then makes an axios POST to 'https://api.mailmodo.com/api/v1/contacts/resubscribe' with the email and API key in headers. Returns an AddContactToListResponse with success/message.
/** * Resubscribes a contact using their email address * @param email - Email address of the contact to unsubscribe * @returns Promise with the API response * @throws Error if email is not provided or if an unexpected error occurs */ export async function resubscribeContact( 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/resubscribe', { email, }, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'mmApiKey': mmApiKey || '' } } ); return {success: true, message: response.data.message}; } 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:275-305 (registration)Registration of the 'resubscribeContact' tool on the MCP server. Defines input schema (email: z.string()), description 'Resubscribe contact in mailmodo', and the async handler that calls resubscribeContact(mmApiKey, params.email) and returns the response.
server.tool( "resubscribeContact", "Resubscribe contact in mailmodo", { email: z.string() }, async (params) => { try { const respone = await resubscribeContact(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 resubscribed '${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)The AddContactToListResponse interface used as the return type of resubscribeContact. Contains success (boolean) and optional message (string).
export interface AddContactToListResponse { // Define your expected response structure here success: boolean; message?: string; } - src/server.ts:6-6 (helper)Import statement for resubscribeContact from the contactManagement module into server.ts.
import { addContactToList, bulkAddContactToList, deleteContact, getAllContactLists, getContactDetails, removeContactFromList, resubscribeContact, unsubscribeContact } from "./apicalls/contactManagement";