proton_send_email
Send emails using Proton Mail with support for plain text or HTML formatting, multiple recipients, and CC/BCC fields.
Instructions
Send a new email. Supports plain text and HTML formats. Recipients can be a single string or array of strings.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | Yes | ||
| cc | No | ||
| bcc | No | ||
| subject | Yes | ||
| body | Yes | ||
| html | No |
Implementation Reference
- src/tools/send.ts:26-61 (handler)The handler logic for the 'proton_send_email' tool, which validates input parameters and calls the 'sendMail' service to send an email via SMTP.
async (params: z.infer<typeof SendEmailSchema>) => { try { // Ensure to, cc, bcc are arrays const toArray = Array.isArray(params.to) ? params.to : [params.to]; const ccArray = params.cc ? (Array.isArray(params.cc) ? params.cc : [params.cc]) : undefined; const bccArray = params.bcc ? (Array.isArray(params.bcc) ? params.bcc : [params.bcc]) : undefined; const messageId = await sendMail({ from: PROTON_USER, to: toArray, cc: ccArray, bcc: bccArray, subject: params.subject, text: !params.html ? params.body : undefined, html: params.html ? params.body : undefined, }); return { content: [ { type: 'text', text: `Email sent successfully!\nMessage ID: ${messageId}\nTo: ${toArray.join(', ')}\nSubject: ${params.subject}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error sending email: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } - src/tools/send.ts:13-62 (registration)Registration of the 'proton_send_email' tool in the MCP server.
server.registerTool( 'proton_send_email', { title: 'Send Email', description: 'Send a new email. Supports plain text and HTML formats. Recipients can be a single string or array of strings.', inputSchema: SendEmailSchema, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false, }, }, async (params: z.infer<typeof SendEmailSchema>) => { try { // Ensure to, cc, bcc are arrays const toArray = Array.isArray(params.to) ? params.to : [params.to]; const ccArray = params.cc ? (Array.isArray(params.cc) ? params.cc : [params.cc]) : undefined; const bccArray = params.bcc ? (Array.isArray(params.bcc) ? params.bcc : [params.bcc]) : undefined; const messageId = await sendMail({ from: PROTON_USER, to: toArray, cc: ccArray, bcc: bccArray, subject: params.subject, text: !params.html ? params.body : undefined, html: params.html ? params.body : undefined, }); return { content: [ { type: 'text', text: `Email sent successfully!\nMessage ID: ${messageId}\nTo: ${toArray.join(', ')}\nSubject: ${params.subject}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error sending email: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); - src/schemas/index.ts:35-42 (schema)Zod schema definition for 'proton_send_email' inputs.
export const SendEmailSchema = z.object({ to: z.union([z.string(), z.array(z.string())]), cc: z.union([z.string(), z.array(z.string())]).optional(), bcc: z.union([z.string(), z.array(z.string())]).optional(), subject: z.string(), body: z.string(), html: z.boolean().default(false), }); - src/services/smtp.ts:41-65 (helper)Service function that handles the actual SMTP email sending using nodemailer.
export async function sendMail(options: MailOptions): Promise<string> { const transporter = getTransporter(); const mailOptions = { from: options.from || PROTON_USER, to: options.to, cc: options.cc, bcc: options.bcc, subject: options.subject, text: options.text, html: options.html, headers: {} as Record<string, string>, }; // Set threading headers if provided if (options.inReplyTo) { mailOptions.headers['In-Reply-To'] = options.inReplyTo; } if (options.references) { mailOptions.headers['References'] = options.references; } const result = await transporter.sendMail(mailOptions); return result.messageId || 'success'; }