> For the complete documentation index, see [llms.txt](https://docs.glesys.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.glesys.com/products/compute/guides-for-server-management/sending-email-from-your-freebsd-server-using-dma.md).

# Sending email from your FreeBSD server using DMA

***

The new mail agent, DMA (DragonFly Mail Agent), for FreeBSD is much easier to configure than the old sendmail server.

DMA is a small, simple mail transfer agent and is used only to send outgoing emails from the host. It does not listen on port 25 for incoming connections, so it won't be able to receive messages from the outside.

DMA doesn't run any daemon, so there's no service to restart after changing the configuration files.

DMA can be used completely standalone; that is, it can send outgoing emails directly to the receiving email server. It can also be used with a smarthost (also called a relay host), such as an ISP's SMTP server, Sendgrid, Glesys's email service, or similar services.

## Standalone

If your FreeBSD machine has a correctly configured hostname, you can start sending outgoing emails directly, without any additional configuration.

However, if you want to send outgoing emails from a different hostname, you set the hostname using the `MAILNAME` variable in `/etc/dma/dma.conf`. For example:

{% code title="Snippet from /etc/dma/dma.conf" %}

```
MAILNAME example.com
```

{% endcode %}

If you want all of your outgoing emails to appear from a single user, you can set this using the `MASQUERADE` option. For example, to always send as the user *info* using the current hostname:

{% code title="Snippet from /etc/dma/dma.conf" %}

```
MASQUERADE info@
```

{% endcode %}

Or, you can set the complete email address, such as:

{% code title="Snippet from /etc/dma/dma.conf" %}

```
MASQUERADE info@example.com
```

{% endcode %}

### Enabling TLS/SSL

If you want to use TLS/SSL for the connections, the following three options are good to enable:

{% code title="Snippet from /etc/dma/dma.conf" %}

```
SECURETRANSFER
STARTTLS
OPPORTUNISTIC_TLS
```

{% endcode %}

This enables TLS/SSL and STARTTLS, but allows unencrypted connections if the receiving host doesn't support it.

## With a smarthost

To use a smarthost (also called a relay host), all you need to do is set the smarthost address and port in `/etc/dma/dma.conf`, and the username and password in `/etc/dma/auth.conf`.

The following is a complete example using Glesys's email service as a smarthost, with TLS/SSL enabled, and all outgoing emails being masqueraded as *<info@example.com>*.

Please note that you need to create an email account before using Glesys's email service as a smarthost. See [Create an email account](/products/other/email/how-tos/create-an-email-account.md) for more information. The `MASQUERADE` email address must match your email account's address.

{% code title="/etc/dma/dma.conf" %}

```
SMARTHOST mail.glesys.se
PORT 587
AUTHPATH /etc/dma/auth.conf
SECURETRANSFER
STARTTLS
OPPORTUNISTIC_TLS
MASQUERADE info@example.com
```

{% endcode %}

The password and username are set in `/etc/dma/auth.conf` using the form `username|smarthost.example.com:password`.

{% code title="/etc/dma/auth.conf" %}

```
info@example.com|mail.glesys.se:xxx1yyy2zzz3
```

{% endcode %}

That's all that's required to start sending emails from your FreeBSD server using Glesys as a smarthost.

## Testing

You can send an email using the built-in `mailx` command. Specify the recipient's email address as a command-line argument. After that, `mailx` starts in interactive mode. You'll first be asked to enter a subject. Press `Enter` once you have typed your subject line. After that, you'll compose the body of the message. Once the body is complete, make a new line by pressing `Enter`, type a single dot on the new line, and then press `Enter` again to send the email. You'll now see the text EOT, meaning *End Of Transmission*.

<pre data-title="Sample mailx session (the command is highlighted)"><code><strong>mailx john@example.org
</strong>Subject: Testing
Hello, this is just a test email.
.
EOT
</code></pre>

## Troubleshooting

The log file `/var/log/maillog` often provides useful hints in case something isn't working.
