# PUT /mail/smarthost

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the mail group.

Set the server's smarthost for outgoing mail

- Who may call it: administrator
- Token scope, any of: mail, all
- Answers: 200 OK

Supply the relay hostname in host. The port defaults to 587, and tls defaults to true, which requires TLS. A nonempty user accepts up to 128 printable ASCII characters without spaces. A nonempty password accepts up to 256 printable ASCII characters without spaces. Values outside these limits or character restrictions return 400.

Omit password to keep the stored password, or set it to null or an empty string to remove it. The 200 response returns the relay settings in smarthost, with has_password indicating whether a password is stored. UrbeStack omits the password itself from the response. Requires an administrator token with the mail scope.

## As a command

- [urbestack-mail-smarthost-set](https://urbestack.com/docs/commands/urbestack-mail-smarthost-set.md): Sets the smarthost for the server's outgoing mail or, with --name, for one domain.

## Request body

JSON, the type [MailSmarthostSet](https://urbestack.com/docs/api/types/MailSmarthostSet.md).

- `host` (string, up to 254 characters, required)
- `password` (string, up to 256 characters or null): Smarthost password. Omit this field to keep the current password, or set it to null or an empty string to remove it.
- `port` (integer, 1 to 65535)
- `tls` (boolean)
- `user` (string, up to 128 characters)

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X PUT "$API/mail/smarthost" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "host": "text",
    "password": "Sup3r-Secret-Passphrase",
    "port": 8443,
    "tls": true,
    "user": "alice"
  }'
```

Response, 200 OK:

```
{
  "smarthost": {
    "has_password": true,
    "host": "text",
    "port": 8443,
    "tls": true,
    "user": "alice"
  }
}
```

## Errors

- 400: '<zone>' is not a zone this machine knows: timedatectl list-timezones names them
- 400: --host is required unless --clear is given
- 400: <what> must be text without control characters, 1 to <max> characters
- 400: A new job is queued or running
- 400: Domain name required
- 400: Domain name too long
- 400: Invalid IPv4 address
- 400: Invalid IPv6 address
- 400: Invalid boolean
- 400: Invalid domain name
- 400: Invalid port
- 400: Invalid setting key
- 400: Job parameters must be an object
- 400: PHP <version> cannot be the default: it is hidden from new choices on this server
- 400: PHP <version> cannot be the default: it is not installed on this server
- 400: The smarthost password must be printable, up to 256 characters
- 400: The smarthost user must be printable, up to 128 characters
- 400: Unknown job type
- 400: Unknown setting '<key>'
- 400: jobs.keep_days (<keep>) may not be smaller than jobs.show_days (<show>): a job cannot be shown longer than it is kept; 0 keeps them for good
- 401: Authentication required
- 404: Setting '<key>' not found
- 409: <key> cannot take that value: <SECOND>{<k>}{on} <sp> (<k>). <SECOND>{<k>}{move}, or choose another
- 409: <key> cannot take that value: the panel listens on port <port> (panel.port). Move the panel first, or choose another
- 409: <s.subject> cannot take port <port>: 
- 409: <s.subject> cannot take port <port>: <why>
- 409: <s.subject> cannot take port <port>: it is the panel's port (panel.port)
- 409: A change is already armed for revert (
- 409: Sharing is required with this license.
- 409: The panel cannot take port <port>: 
- 409: The panel cannot take port <port>: <why>
- 409: These are the nameservers of a distribution network with several nodes, and every node lists the same ones. To remove a nameserver or move it to another node, use the actions beside its name on DNS zones › Nameservers & addresses, or urbestack-dns-nameserver
