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

# 发送电子邮件

> 通过 YCloud 发送 HTML 或纯文本电子邮件。

在发送之前，请在您的 YCloud 账户中注册并激活发件人域名。

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl --request POST https://api.ycloud.com/v2/emails \
  --header "X-API-Key: $YCLOUD_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "from": "Support Team<support@example.com>",
    "to": "customer@example.com",
    "subject": "Welcome",
    "contentType": "text/html",
    "content": "<h1>Welcome</h1><p>Thanks for joining us.</p>",
    "externalId": "welcome-10001"
  }'
```

## 必填字段

| 字段 | 描述 |
| - | - |
| `from` | 已激活域名上的发件人地址。显示名称为可选。 |
| `to` | 一个或多个以逗号分隔的收件人地址。最多 100 个收件人。 |
| `subject` | 主题行。最大长度为 255 个字符。 |
| `content` | 电子邮件正文。最大大小为 150 KB。 |

将 `contentType` 设置为 `text/html` 或 `text/plain`。`text/plain` 消息不计算点击和打开事件。

该请求还支持 `cc`、`bcc`、`replyTo`、`summary`、`variables`、`externalId` 和 `callbackUrl`。

## 个性化内容

在内容中的 `#` 字符之间放置变量。为 `to` 中的每个地址提供一个变量对象。

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "to": "alice@example.com,bob@example.com",
  "content": "Hello #name#!",
  "variables": [
    { "name": "Alice" },
    { "name": "Bob" }
  ]
}
```

订阅 `email.delivery.updated` Webhook 以接收 `delivered` 和 `failed` 的状态更改。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.