> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/handbook/di-32-zhang-dian-zi-you-jian/32.3.-dma.md).

# 32.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 上监听传入连接。

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

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

### 32.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
```

### 32.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
```

### 32.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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/handbook/di-32-zhang-dian-zi-you-jian/32.3.-dma.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
