Skip to main content
Glama
SpasticPalate

Proton MCP Server

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
NameRequiredDescriptionDefault
toYes
ccNo
bccNo
subjectYes
bodyYes
htmlNo

Implementation Reference

  • 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)}`,
            },
          ],
        };
      }
    }
  • 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)}`,
              },
            ],
          };
        }
      }
    );
  • 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),
    });
  • 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';
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SpasticPalate/proton-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server