[comment]: # ({473c0010-d40475f4})
# 1 电子邮件

[comment]: # ({/473c0010-d40475f4})

[comment]: # ({860d77dd-9d59e93d})
#### 概述

要将电子邮件配置为消息的传递通道，您需要将电子邮件配置为媒介类型，并为用户分配特定地址。

::: noteclassic
针对同一事件的多个通知将在同一电子邮件线程中分组显示。

:::

[comment]: # ({/860d77dd-9d59e93d})

[comment]: # ({5a73e45c-3711e99d})
#### 配置

要将 email 配置为 media type：

1. 转到 *Alerts > Media types*。
2. 单击 *Create media type*（或在预定义 media types 列表中单击 *Email*）。

**Media type** 选项卡包含通用 media type 属性：

![](../../../../../assets/en/manual/config/notifications/media/media_email.png){width="600"}

所有必填输入字段都用红色星号标记。

:::notewarning
导出 email media type 配置时，Password 会以明文导出。
:::

以下参数是 email media type 的专用参数：

|Parameter|Description|
|--|--------|
|*Email provider*|选择 email 提供商：*Generic SMTP*、*Gmail*、*Gmail relay*、*Office365* 或 *Office365 relay*。<br>如果选择与 Gmail/Office365 相关的选项，则只需提供发件人 email 地址和密码；*SMTP server*、*SMTP server port*、*SMTP helo* 和 *Connection security* 等选项将由 Zabbix 自动填充。另请参见：[Automated Gmail/Office365 media types](/manual/config/notifications/media#automated-gmailoffice365-media-types)。 |
|*SMTP server*|设置用于处理外发消息的 SMTP 服务器。<br>当选择 *Generic SMTP* 作为 email 提供商时，此字段可用。|
|*SMTP server port*|设置用于处理外发消息的 SMTP 服务器端口。<br>当选择 *Generic SMTP* 作为 email 提供商时，此字段可用。|
|*Email*|此处输入的地址将用作发送消息的 **From** 地址。<br>支持添加发件人显示名称（例如上方截图中的 *Zabbix\_info <zabbix\@company.com>*）。<br>与 RFC 5322 允许的内容相比，Zabbix email 中对显示名称有一些限制，如下例所示：<br>有效示例：<br>*zabbix\@company.com*（仅 email 地址，无需使用尖括号）<br>*Zabbix\_info <zabbix\@company.com>*（显示名称和尖括号中的 email 地址）<br>*∑Ω-monitoring <zabbix\@company.com>*（显示名称中包含 UTF-8 字符）<br>无效示例：<br>*Zabbix HQ zabbix\@company.com*（有显示名称，但 email 地址周围没有尖括号）<br>*"Zabbix\\@\\<H(comment)Q\\>" <zabbix\@company.com>*（尽管符合 RFC 5322，但 Zabbix email 不支持 quoted pairs 和 comments）|
|*SMTP helo*|设置正确的 SMTP helo 值，通常为域名。<br>如果留空，将发送 email 的域名（即 *Email* 字段中 `@` 后面的内容）。如果无法获取域名，将记录一条调试级别警告，并发送服务器主机名作为 HELO 命令的域名。<br>当选择 *Generic SMTP* 作为 email 提供商时，此字段可用。|
|*Connection security*|选择连接安全级别：<br>**None** - 不使用 [CURLOPT\_USE\_SSL](http://curl.haxx.se/libcurl/c/CURLOPT_USE_SSL.html) 选项<br>**STARTTLS** - 使用 CURLOPT\_USE\_SSL 选项，值为 CURLUSESSL\_ALL<br>**SSL/TLS** - 可选使用 CURLOPT\_USE\_SSL|
|*SSL verify peer*|勾选此复选框以验证 SMTP 服务器的 SSL 证书。<br>应将服务器配置指令 "SSLCALocation" 的值放入 [CURLOPT\_CAPATH](http://curl.haxx.se/libcurl/c/CURLOPT_CAPATH.html) 以进行证书验证。<br>这会设置 cURL 选项 [CURLOPT\_SSL\_VERIFYPEER](http://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html)。|
|*SSL verify host*|勾选此复选框以验证 SMTP 服务器证书的 *Common Name* 字段或 *Subject Alternate Name* 字段是否匹配。<br>这会设置 cURL 选项 [CURLOPT\_SSL\_VERIFYHOST](http://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html)。|
|*Authentication*|选择认证级别：<br>**None** - 不设置 cURL 选项<br>**Username and password** - 表示 "AUTH=\*"，由 cURL 决定认证机制|
|*Username*|用于认证的用户名。<br>这会设置 [CURLOPT\_USERNAME](http://curl.haxx.se/libcurl/c/CURLOPT_USERNAME.html) 的值。<br>支持 [User macros](/manual/appendix/macros/supported_by_location_user#other-locations)。|
|*Password*|用于认证的密码。<br>这会设置 [CURLOPT\_PASSWORD](http://curl.haxx.se/libcurl/c/CURLOPT_PASSWORD.html) 的值。<br>支持 [User macros](/manual/appendix/macros/supported_by_location_user#other-locations)。<br>此处输入的值在导出 media type 配置时会按原样导出。为避免在导出的文件中暴露敏感凭据，请使用 user macro（例如 `{$EMAIL_SMTP_PASSWORD}`）代替字面量密码——导出时会保留 macro 引用，而密钥值应在目标系统上（重新）配置。|
|*Message format*|选择消息格式：<br>**HTML** - 以 HTML 发送<br>**Plain text** - 以纯文本发送|

::: noteimportant
要启用 SMTP 认证，Zabbix 服务器必须使用 `--with-libcurl` [编译](/manual/installation/install#configure-the-sources) 选项进行编译，该选项需要 libcurl（版本详情请参见 [server](/manual/installation/requirements#serverproxy) 要求）。
:::

另请参见 [common media type parameters](/manual/config/notifications/media#common-parameters)，了解如何配置默认消息和告警处理选项。

[comment]: # ({/5a73e45c-3711e99d})

[comment]: # ({50e8f033-98f29ec0})


#### 测试

要测试配置的电子邮件媒介类型是否正常工作：

1. 在[概述](/manual/config/notifications/media#概述)中找到相关的电子邮件媒介类型。
2. 点击列表最后一列的*测试*按钮（将打开测试窗口）。
3. 输入*发送至*收件人地址、消息正文以及可选的邮件主题。
4. 点击*测试*发送测试消息。

测试成功或失败消息将在同一窗口中显示：

![](../../../../../assets/en/manual/config/notifications/media/test_email0.png){width="600"}

[comment]: # ({/50e8f033-98f29ec0})

[comment]: # ({859be4b6-5e74f274})
#### 用户媒介

配置好电子邮件媒介类型后，转到 *Users > Users* 部分并编辑用户配置文件，为该用户分配电子邮件媒介。
适用于所有媒介类型的用户媒介设置步骤，请参见 [Media types](/manual/config/notifications/media#user-media) 页面。

[comment]: # ({/859be4b6-5e74f274})
