sendEmailToCampaign
Send personalized emails for campaigns using Mailmodo by specifying campaign ID, recipient email, and optional overrides like subject, sender name, or reply-to address.
Instructions
Trigger and email for email campaign trigger with personalization parameter added to the email template.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| addToList | No | Optional: List ID to which the contact should be added as part of triggering the campaign. | |
| campaignId | Yes | Camapign id of the campaign to be triggered | |
| campaign_data | No | Optional: Transient personalization parameters, not stored in the contact profile. | |
| data | No | Optional: Personalization parameters saved to the contact's profile. | |
| Yes | Email address of the contact to whom you want to send the email. This is required. | ||
| fromName | No | Optional: Overrides the sender name for the campaign. | |
| replyTo | No | Optional: Overrides the default reply-to email address for the campaign. | |
| subject | No | Optional: Overrides the default subject line provided when creating the campaign. |
Implementation Reference
- src/server.ts:413-437 (handler)The execution logic for the sendEmailToCampaign tool. It destructures parameters, calls the triggerMailmodoCampaign helper with API key and params, and returns success/error text content.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:376-412 (schema)Zod schema defining the input parameters for the sendEmailToCampaign tool, including required campaignId and email, and various optional personalization and override fields.{ 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."), },
- src/server.ts:373-438 (registration)Registration of the 'sendEmailToCampaign' MCP tool on the McpServer instance, including name, description, input schema, and handler function.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 }; } } );
- TypeScript type definition for TriggerCampaignRequest, matching the tool's input parameters (excluding campaignId), used by the triggerMailmodoCampaign helper.export interface TriggerCampaignRequest { email: string; subject?: string; replyTo?: string; fromName?: string; campaign_data?: Record<string, string>; data?: Record<string, string>; addToList?: string; }