Skip to main content
Glama
sendEmailHelper.ts1.28 kB
import { Resend } from 'resend'; import { useLogger } from './logger'; import { validateContent } from './validateContent'; import { createResendClient } from './createResendClient'; // 通用邮件发送函数,支持单个和批量发送 export const sendEmailHelper = async ( from: string, to: string | string[], subject: string, text: string | undefined, html: string | undefined, logger: ReturnType<typeof useLogger> ) => { validateContent(text, html); const { resend, emailHost } = createResendClient(); try { const toArray = Array.isArray(to) ? to : [to]; logger.info( `Sending email to ${toArray.length} recipient(s) with subject "${subject}"` ); const result = await resend.emails.send({ from: `${from} <no-reply@${emailHost}>`, to: toArray, subject, text, html, react: null, }); logger.info(`Email sent successfully with ID: ${result.data?.id}`); // 如果是单个收件人,返回简单结果;如果是多个收件人,返回详细结果 return result; } catch (error) { logger.error( `Failed to send email to ${Array.isArray(to) ? to.join(', ') : to}: ${ error instanceof Error ? error.message : String(error) }` ); throw error; } };

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/pidanmeng/resend-mcp'

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