> ## Documentation Index
> Fetch the complete documentation index at: https://docs.insforge.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# 电子邮件 SDK 参考

> 使用 InsForge SDK 发送自定义事务电子邮件

<CodeGroup>
  ```bash npm theme={null}
  npm install @insforge/sdk@latest
  ```

  ```bash yarn theme={null}
  yarn add @insforge/sdk@latest
  ```

  ```bash pnpm theme={null}
  pnpm add @insforge/sdk@latest
  ```
</CodeGroup>

```javascript theme={null}
import { createClient } from '@insforge/sdk';

const insforge = createClient({
  baseUrl: 'https://your-app.insforge.app',
  anonKey: 'your-anon-key'  // Optional: for public/unauthenticated requests
});
```

Find the anon key with `npx @insforge/cli secrets get ANON_KEY`, or in the dashboard: click **Install** and open **API Keys**.

## emails.send()

向一个或多个收件人发送自定义 HTML 电子邮件。

### 参数

* `to` (string | string\[], required) - 收件人电子邮件，最多 50 个收件人
* `subject` (string, required) - 电子邮件主题行，最多 500 个字符
* `html` (string, required) - 电子邮件的 HTML 内容
* `cc` (string | string\[], optional) - 抄送收件人，最多 50 个收件人
* `bcc` (string | string\[], optional) - 密送收件人，最多 50 个收件人
* `from` (string, optional) - 自定义发件人名称，最多 100 个字符
* `replyTo` (string, optional) - 回复电子邮件地址，必须是有效的电子邮件地址

<Note>
  当为您的项目启用[自定义 SMTP](/core-concepts/messaging/custom-smtp) 时，`from` 字段将被忽略。发件人名称和电子邮件始终取自您的 SMTP 配置，以防止通过您的服务器进行欺骗。
</Note>

### 返回

```typescript theme={null}
{
  data: {} | null,  // Empty object on success
  error: Error | null
}
```

### 示例

```javascript theme={null}
const { data, error } = await insforge.emails.send({
  to: ['user1@example.com', 'user2@example.com'],
  cc: 'manager@example.com',
  from: 'Acme Support Team',
  subject: 'Team Update',
  html: '<h1>Weekly Update</h1><p>Here are this week\'s highlights...</p>',
  replyTo: 'support@example.com'
});

if (error) {
  console.error('Failed to send email:', error.message);
  return;
}

console.log('Email sent successfully');
```
