> ## 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');
```
