Bỏ qua để đến nội dung
Playbook: mail domains and mailboxes Set up the workspace mail host, install the mail stack, add mail domains, mailboxes, aliases and forwarding, publish DNS, test delivery, and read or send mail with mailbox-scoped tokens.

Playbook: mail domains and mailboxes

Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.

MZPanel runs one mail host per workspace: a server with Postfix, Dovecot, OpenDKIM, Rspamd/ClamAV and the box webmail. Domains and mailboxes are job kinds on that host. The host choice and the sending providers are control-plane settings.

Token: operate for domains, mailboxes and aliases. Installing or uninstalling the stack and choosing the host need full. Deleting domains or mailboxes needs full + data:delete. Reading or sending messages needs mail:read, mail:send or mail:modify, optionally narrowed with a mailScope allowlist (see Tokens, levels & scopes).

  1. mail_settings_get shows the current host server and primary login domain.
  2. mail_settings_set {body: {hostServerId: <server UUID>, primaryLoginDomain: "mail.example.com"}} (full).
  3. On that server, run jobs_create {id, body: {type: "mail.preflight"}} (read) to check readiness (checks[]: port25, rdns, blacklist, inbound_ports — the last lists firewall-blocked mail ports in blocked[]; open them with security.fw {op: "add", port, proto: "tcp", action: "allow", noRevert: true}), then {type: "mail.install"} (full) and poll jobs_get.
  4. Set the mail hostname: mail.hostname-set {hostname: "mail.example.com", cert: true}.
  5. Verify: jobs_create mail.status or servers_inventory {id, kind: "mail"}.

All of these are jobs_create on the mail host:

NeedJob kind (body)
Add a mail domainmail.domain-add {domain}
Add a mailboxmail.mailbox-add {address, password?, name?, title?, quotaMb?, invite?, welcome?} (password is required unless invite: true)
Change a password or quotamail.mailbox-passwd {address, password} · mail.mailbox-quota {address, quotaMb}
Aliasmail.alias-set {address, targets} · remove: mail.alias-del
Forward a mailboxmail.mailbox-forward {address, to?, keep?}
Catch-allmail.catchall-set {domain, target?}
Groups and shared mailboxesmail.group-set · mail.shared-set (read jobs_schema for the fields)
Suspend or offboardmail.mailbox-suspend · mail.mailbox-offboard (full + data:delete)
Removemail.mailbox-del · mail.domain-del (full + data:delete)

The fleet-wide view is servers_mail_all, which lists domains, mailboxes and aliases on every server.

The domain needs MX, SPF, DKIM and DMARC records that point at the mail host. The dashboard Mail page (/mail) shows the exact values. Publish them in a connected zone with dns_records_create (see DNS, TLS and SSL), then check with jobs_create mail.preflight and dns.lookup.

Sending through a provider (better inbox placement, or when port 25 is blocked):

  • Cloudflare Email Sending: mail_cf_sending_setup {domain} → mail_cf_sending_apply {domain, body: {serverId: <mail host>, token}} (full; token is a separate Cloudflare token with only Email Sending: Edit, and the server must be online).
  • Resend or Amazon SES: mail_providers_create (full + webhooks:admin) → mail_provider_domain_add {id, body: {domain}} (publishes DKIM/SPF to Cloudflare) → mail_provider_domain_check until verified → mail_provider_apply {id, body: {serverId: <mail host>}}.
  • Plain SMTP relay on the box: mail.send-set {enabled, relayHost, relayPort, relayUser, relayPass}. A relayPass (or the pass of mail.routes-smtp) is sealed to the server, never put on the job argv, so it needs agent 0.2.157+: 409 agent_update_required means run agent_update first; 409 server_key_missing means wait for the agent to reconnect.
  • The same applies, from agent 0.2.161, to every other credential you hand a mail or database job: the password of mail.mailbox-add / mail.mailbox-passwd, the pass of mail.import, db.create, db.user-create and db.user-passwd, the token of mail.send-cf and mail_cf_sending_apply, and the provider key of mail_providers_create. They are sealed to the server, so args and the audit log never show them; on an older agent these calls answer 409 agent_update_required (details.required: "0.2.161") instead of running. A mailbox invite and a DB user whose password the server generates need no update.

Forward-only domains (no mailboxes) can use Cloudflare Email Routing instead: mail_cf_enable {domain} → mail_cf_destination_add → mail_cf_rule_create {domain, body: {address, destinations}}.

  • mail.test-send {to, from?} sends a test message.
  • Send routes (primary + fallbacks): mail.routes-get (order, what is set up, per-route stats, spf_needed) → mail.routes-set {routes: ["direct","cloudflare","resend"]} (primary first; each route must be set up already: Cloudflare/Resend/SES via the tools above, a custom relay via mail.routes-smtp {host, port?, user?, pass?, tls?}). mail.routes-test {kind, to, from?} sends through ONE route and returns {ok, class, reply, ms} (ok:false is a refusal, not a job failure). When a route refuses for its own reason the server tries the next; an unknown recipient stops it.
  • mail.delivery-log {hours?, status?, q?, limit?} shows recent deliveries (sent, deferred, bounced, rejected).
  • mail.queue / mail.flush show and flush the queue (mail.queue-del needs data:delete). mail.sent-stats and mail.dmarc-report report on volume and DMARC.

With a token that has the mail scopes:

  • mail_folders {serverId, address} and mail_messages_list {serverId, address, query: {folder?, q?, scope?}} (mail:read).
  • mail_message_get {serverId, address, uid, query: {folder}} and mail_attachment_get (mail:read).
  • mail_draft_save saves a draft for a person to review (mail:read).
  • mail_message_send sends from that mailbox’s own address (full + mail:send). Confirm with the human first.
  • mail_messages_modify {serverId, address, action: flag|move|delete, body} (mail:modify).

Webmail sign-in links (mail.webmail-login), webmail rollout (mail.webmail-update) and mailbox API keys (mail.apikey-*) are dashboard-only.