send_email
Send emails through Hiworks Mail MCP server with support for text, HTML content, attachments, CC, and BCC recipients.
Instructions
하이웍스 이메일을 전송합니다.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| username | No | ||
| password | No | ||
| to | Yes | ||
| subject | Yes | ||
| text | No | ||
| html | No | ||
| cc | No | ||
| bcc | No | ||
| attachments | No |
Implementation Reference
- src/index.ts:323-372 (handler)The main execution logic for the send_email tool. Creates an SMTP transporter using the provided credentials and sends the email with nodemailer, returning success or error response.async ({ username, password, to, subject, text, html, cc, bcc, attachments }) => { try { log('Creating SMTP transporter...'); const transporter = await createSMTPTransporter(username, password); const mailOptions = { from: username, to, subject, text, html, cc, bcc, attachments }; log('Sending email...'); const info = await transporter.sendMail(mailOptions); log('Email sent successfully:', info.messageId); return { content: [ { type: "text", text: JSON.stringify({ success: true, messageId: info.messageId } as SendEmailResponse) } ] }; } catch (error: any) { log('Error sending email:', error); return { content: [ { type: "text", text: JSON.stringify({ success: false, error: error.message } as SendEmailResponse) } ] }; } } ); // 메인 함수 async function main() {
- src/index.ts:307-373 (registration)Registration of the send_email tool on the MCP server, specifying name, description, Zod input schema, and handler function.server.tool( 'send_email', '하이웍스 이메일을 전송합니다.', { ...emailSchema, to: z.string(), subject: z.string(), text: z.string().optional(), html: z.string().optional(), cc: z.array(z.string()).optional(), bcc: z.array(z.string()).optional(), attachments: z.array(z.object({ filename: z.string(), content: z.union([z.string(), z.instanceof(Buffer)]) })).optional() }, async ({ username, password, to, subject, text, html, cc, bcc, attachments }) => { try { log('Creating SMTP transporter...'); const transporter = await createSMTPTransporter(username, password); const mailOptions = { from: username, to, subject, text, html, cc, bcc, attachments }; log('Sending email...'); const info = await transporter.sendMail(mailOptions); log('Email sent successfully:', info.messageId); return { content: [ { type: "text", text: JSON.stringify({ success: true, messageId: info.messageId } as SendEmailResponse) } ] }; } catch (error: any) { log('Error sending email:', error); return { content: [ { type: "text", text: JSON.stringify({ success: false, error: error.message } as SendEmailResponse) } ] }; } } ); // 메인 함수 async function main() { if (process.env.NODE_ENV === 'development') {
- src/types/mail.ts:39-58 (schema)TypeScript interfaces defining the input (SendEmailParams) and output (SendEmailResponse) types for the send_email tool, imported and used in index.ts.export interface SendEmailParams { username?: string; password?: string; to: string; subject: string; text?: string; html?: string; cc?: string[]; bcc?: string[]; attachments?: Array<{ filename: string; content: string | Buffer; }>; } export interface SendEmailResponse { success: boolean; messageId?: string; error?: string; }
- src/index.ts:59-69 (helper)Helper function to create a nodemailer SMTP transporter configured for Hiworks SMTP server using the provided username and password.async function createSMTPTransporter(username: string, password: string) { return nodemailer.createTransport({ host: config.smtp.host, port: config.smtp.port, secure: config.smtp.secure, auth: { user: username, pass: password } }); }