# 31.3.DragonFly 邮件代理（DMA）

DragonFly Mail Agent (DMA) 是从 FreeBSD 版本 14.0 开始的默认 MTA。[dma(8)](https://man.freebsd.org/cgi/man.cgi?query=dma\&sektion=8\&format=html) 是一款小型的邮件传输代理（MTA），设计用于家庭和办公室使用。它接受来自本地安装的邮件用户代理（MUA）的邮件，并将邮件传递到本地或远程目的地。远程传递包括多个功能，如 TLS/SSL 支持和 SMTP 身份验证。

[dma(8)](https://man.freebsd.org/cgi/man.cgi?query=dma\&sektion=8\&format=html) 并不打算取代真正的大型 MTA，如 [sendmail(8)](https://man.freebsd.org/cgi/man.cgi?query=sendmail\&sektion=8\&format=html) 或 [postfix(1)](https://man.freebsd.org/cgi/man.cgi?query=postfix\&sektion=1\&format=html)。因此，[dma(8)](https://man.freebsd.org/cgi/man.cgi?query=dma\&sektion=8\&format=html) 不会在端口 25 上监听传入连接。

## 31.3.1. 配置 DragonFly Mail Agent (DMA)

DMA 提供了一个默认配置，适合许多部署。自定义设置可以在 **/etc/dma/dma.conf** 中定义，SMTP 身份验证配置在 **/etc/dma/auth.conf** 中。

### 31.3.1.1. 使用 DMA 通过 Gmail 路由传出邮件（STARTTLS:SMTP 示例）

这个示例 **/etc/dma/dma.conf** 可用于通过 Google 的 SMTP 服务器发送邮件。

```ini
SMARTHOST smtp.gmail.com
PORT 587
AUTHPATH /etc/dma/auth.conf
SECURETRANSFER
STARTTLS
MASQUERADE username@gmail.com
```

可以通过在 **/etc/dma/auth.conf** 中添加一行来设置身份验证：

```ini
username@gmail.com|smtp.gmail.com:password
```

> **注意**
>
> 如果你启用了双重身份验证，你需要生成一个应用专用密码，因为你的普通登录密码会被拒绝。有关 [应用专用密码](https://myaccount.google.com/apppasswords) 的更多信息，请参阅 Google 文档。

执行以下命令以测试配置：

```sh
% echo this is a test | mail -v -s testing-email username@gmail.com
```

### 31.3.1.2. 使用 DMA 通过 Fastmail 路由传出邮件（SSL/TLS 示例）

这个示例 **/etc/dma/dma.conf** 可用于通过 Fastmail 的 SMTP 服务器发送邮件。

```ini
SMARTHOST smtp.fastmail.com
PORT 465
AUTHPATH /etc/dma/auth.conf
SECURETRANSFER
MAILNAME example.server.com
```

可以通过在 **/etc/dma/auth.conf** 中添加一行来设置身份验证：

```ini
username@fastmail.com|smtp.fastmail.com:password
```

执行以下命令以测试配置：

```sh
% echo this is a test | mail -v -s testing-email username@fastmail.com
```

### 31.3.1.3. 使用 DMA 通过自定义邮件主机路由传出邮件

这个示例 **/etc/dma/dma.conf** 可用于通过自定义邮件主机发送邮件。

```ini
SMARTHOST mail.example.org
PORT 587
AUTHPATH /etc/dma/auth.conf
SECURETRANSFER
STARTTLS
```

可以通过在 **/etc/dma/auth.conf** 中添加一行来设置身份验证：

```ini
username@example.org|mail.example.org:password
```

执行以下命令以测试配置：

```sh
% echo this is a test | mail -v -s testing-email username@example.org
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://handbook.bsdcn.org/di-31-zhang-dian-zi-you-jian/31.3.-dma.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
