sendEmailToCampaign
Send a triggered email to a campaign recipient by providing campaign ID and email address, with support for personalization parameters and optional overrides for subject, reply-to, sender name, and list addition.
Instructions
Trigger and email for email campaign trigger with personalization parameter added to the email template.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| campaignId | Yes | Camapign id of the campaign to be triggered | |
| Yes | Email address of the contact to whom you want to send the email. This is required. | ||
| subject | No | Optional: Overrides the default subject line provided when creating the campaign. | |
| replyTo | No | Optional: Overrides the default reply-to email address for the campaign. | |
| fromName | No | Optional: Overrides the sender name for the campaign. | |
| campaign_data | No | Optional: Transient personalization parameters, not stored in the contact profile. | |
| data | No | Optional: Personalization parameters saved to the contact's profile. | |
| addToList | No | Optional: List ID to which the contact should be added as part of triggering the campaign. |
Implementation Reference
- src/server.ts:373-438 (registration)Registration of the 'sendEmailToCampaign' tool on the MCP server using server.tool(), including the full schema definition for all parameters (campaignId, email, subject, replyTo, fromName, campaign_data, data, addToList).
server.tool( "sendEmailToCampaign", "Trigger and email for email campaign trigger with personalization parameter added to the email template. ", { campaignId: z.string().describe('Camapign id of the campaign to be triggered'), email: z .string() .email({ message: "Invalid email address" }) .describe("Email address of the contact to whom you want to send the email. This is required."), subject: z .string() .optional() .describe("Optional: Overrides the default subject line provided when creating the campaign."), replyTo: z .string() .optional() .describe("Optional: Overrides the default reply-to email address for the campaign."), fromName: z .string() .optional() .describe("Optional: Overrides the sender name for the campaign."), campaign_data: z .record(z.string()) .optional() .describe("Optional: Transient personalization parameters, not stored in the contact profile."), data: z .record(z.string()) .optional() .describe("Optional: Personalization parameters saved to the contact's profile."), addToList: z .string() .optional() .describe("Optional: List ID to which the contact should be added as part of triggering the campaign."), }, async (params) => { try { const { campaignId, ...newparams } = params; const respone = await triggerMailmodoCampaign(mmApiKey, params.campaignId, newparams); // 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.message ?`Successfully sent email to '${params.email} for the campaignId ${params.campaignId} 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 delete", }], isError: true }; } } ); - src/server.ts:413-437 (handler)Handler function for 'sendEmailToCampaign' that extracts campaignId from params and delegates to triggerMailmodoCampaign API call, with error handling and response formatting.
async (params) => { try { const { campaignId, ...newparams } = params; const respone = await triggerMailmodoCampaign(mmApiKey, params.campaignId, newparams); // 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.message ?`Successfully sent email to '${params.email} for the campaignId ${params.campaignId} 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 delete", }], isError: true }; } } - src/apicalls/sendCampaign.ts:11-36 (helper)Helper function 'triggerMailmodoCampaign' that makes an HTTP POST to the Mailmodo API to trigger a campaign for a single email recipient.
export async function triggerMailmodoCampaign( mmApiKey: string, campaignId: string, payload: TriggerCampaignRequest ): Promise<TriggerCampaignResponse> { try { const response = await axios.post<TriggerCampaignResponse>( `https://api.mailmodo.com/api/v1/triggerCampaign/${campaignId}`, payload, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'mmApiKey': mmApiKey || '' } } ); return response.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Failed to trigger Mailmodo campaign: ${error.response?.data?.message || error.message}`); } throw error; } } - TypeScript interfaces: TriggerCampaignRequest (input schema with email, subject, replyTo, fromName, campaign_data, data, addToList) and TriggerCampaignResponse (output schema with success, message, ref).
export interface TriggerCampaignRequest { email: string; subject?: string; replyTo?: string; fromName?: string; campaign_data?: Record<string, string>; data?: Record<string, string>; addToList?: string; } export interface TriggerCampaignResponse { success: boolean; message: string; ref: string; }