Zimbra Command Line: 8 Proven Queue and LDAP Fixes

This is my collection of Zimbra command line snippets for the LDAP and MTA servers: looking up an account in LDAP, fixing a zmconfigd start failure, reading the mail log, counting SMTP connections and managing the Postfix queue. The commands come from running Zimbra 8.x in production. For this update every Postfix command was re-run on a test system, and three of the original one-liners turned out to be wrong: the SMTP counter always prints 0, the MAILER-DAEMON cleanup loop skips held messages, and the queue tuning can bounce mail after 15 minutes.

Lab note for these Zimbra commands: Zimbra itself is not installed for this test. The Postfix commands run on Postfix 3.10.13 in a debian:13 container whose queue was filled with three messages to an unreachable relay and two bounces with an empty sender, which Postfix shows as MAILER-DAEMON. Zimbra ships its own Postfix under /opt/zimbra/common/sbin (older releases used /opt/zimbra/postfix/sbin), and the commands are the same; run them as the zimbra user unless a step says root.

Zimbra command line for the LDAP server

The first Zimbra command line tool on an LDAP server is ldapsearch. To print every attribute of one user straight from the Zimbra LDAP directory, bind as the Zimbra LDAP admin and search by uid:

ldapsearch -LLL -x -H ldap://ldap.huuphan.local \
  -D "uid=zimbra,cn=admins,cn=zimbra" -W \
  -b dc=huuphan,dc=local "(uid=huupv)"

Two changes from the original command. The filter (&(uid=huupv)) is an AND with a single term, so plain (uid=huupv) does the same. And -w password put the LDAP admin password on the command line, where any local user can read it in ps while the search runs; -W asks for it instead. The password itself is in zmlocalconfig -s zimbra_ldap_password. For most daily checks you do not need raw LDAP at all: zmprov ga user@domain shows the same account through the Zimbra tools, as in how to check Zimbra account status. Raw LDAP filters are still the fastest way to search many accounts at once, for example to find accounts that are not active.

Zimbra command line for the MTA server

Starting zmconfigd... failed

On one of my MTA servers the Zimbra command zmcontrol start stopped at this message:

Host mta.huuphan.local
        Starting zmconfigd...Failed.
Starting zmconfigd...failed.

On that server the cause was the loopback line in /etc/hosts. Commenting it out fixed the start:

# vim /etc/hosts
#127.0.0.1   localhost.localdomain localhost

Treat this as one cause, not the general fix. zmconfigd is the process that, in the words of the Zimbra Administrator's Guide, "polls the LDAP directory every two minutes for modifications and updates the Postfix configuration files". If it cannot resolve the server's own name or reach LDAP, it fails to start. Check that the host's FQDN in /etc/hosts points to its real IP before you remove anything, and keep a localhost entry if other services need it.

Show errors and warnings from the mail log

Most Zimbra command line troubleshooting on the MTA starts with the log. Zimbra sends Postfix, Amavis and its own MTA messages to /var/log/zimbra.log. This filter shows only rejections and problems:

$ grep -E '(reject|warning|error|fatal|panic):' /tmp/zimbra.log
Nov  6 10:00:01 mta postfix/smtp[123]: warning: connect to 192.0.2.1[192.0.2.1]:25: Connection timed out
Nov  6 10:00:02 mta postfix/smtpd[124]: NOQUEUE: reject: RCPT from unknown[203.0.113.9]: 554 5.7.1 Relay access denied

The original used egrep, which gave the same two lines on Debian 13; grep -E is the standard form and keeps working where egrep is a deprecated wrapper.

Count established SMTP connections

The original one-liner for this Zimbra command line task always returns 0. With two clients connected to port 25 in the lab:

$ netstat -nplt | awk '{print $4 " " $6}' | egrep '[0-9]+.[0-9]+.[0-9]+.[0-9]+:25'
127.0.0.1:25 LISTEN

$ netstat -nplt | awk '{print $4 " " $6}' | egrep '[0-9]+.[0-9]+.[0-9]+.[0-9]+:25' | egrep 'ESTABLISHED' | wc -l
0

The -l option lists only listening sockets, so there is never an ESTABLISHED line to count. Drop -l and match the local port exactly, or use ss:

$ netstat -nt | awk '$4 ~ /:25$/ && $6 == "ESTABLISHED"' | wc -l
2
$ ss -Htn state established '( sport = :25 )' | wc -l
2

Manage the Postfix queue from the Zimbra command line

The queue is where the Zimbra command line saves the most time. To list the queue, postqueue -p and mailq print the same table. On Zimbra you can also run sudo ~/libexec/zmqstat for counts per queue. In the lab:

$ postqueue -p | grep -E '^[0-9A-F]|Requests'
2F704D37688     275 Fri Nov  6 07:15:37  alice@example.test
2D53BD37686     275 Fri Nov  6 07:15:37  alice@example.test
38954D3768F     293 Fri Nov  6 07:15:37  MAILER-DAEMON
33836D3768B     275 Fri Nov  6 07:15:37  alice@example.test
3D18DD37691     293 Fri Nov  6 07:15:37  MAILER-DAEMON
-- 1 Kbytes in 5 Requests.

Read one queued message

postcat -q takes a queue ID and prints the envelope and the message; -h limits it to the headers:

$ postcat -q 2F704D37688 | grep -E '^(\*\*\* |sender:|recipient:|Subject:)'
*** ENVELOPE RECORDS deferred/2/2F704D37688 ***
sender: alice@example.test
recipient: bob@example.org
*** MESSAGE CONTENTS deferred/2/2F704D37688 ***
Subject: test 2
*** HEADER EXTRACTED deferred/2/2F704D37688 ***
*** MESSAGE FILE END deferred/2/2F704D37688 ***
$ postcat -hq 2F704D37688 | grep -E '^(From|To|Subject):'
Subject: test 2
From: root <alice@example.test>

Delete all MAILER-DAEMON messages

After a spam run (or a compromised account) the queue can fill with bounces nobody will receive. The original loop (run as root):

for i in `postqueue -p|grep 'MAILER-DAEMON' |awk {'print $1'}|grep -v 'MAILER-DAEMON'`; do postsuper -d $i ; done

It works until a bounce is on hold or being delivered. postqueue -p then adds ! (hold) or * (active) to the queue ID, and postsuper rejects the ID with the suffix. One bounce was put on hold with postsuper -h before running the loop:

Zimbra command line: the old MAILER-DAEMON loop fails on a held message, postqueue -j works
The old loop removes one bounce and fails on the held one; the JSON version removes all of them.
$ postqueue -p | grep MAILER-DAEMON
3D18DD37691     293 Fri Nov  6 07:15:37  MAILER-DAEMON
38954D3768F!     293 Fri Nov  6 07:15:37  MAILER-DAEMON

$ bash old_loop.sh
postsuper: 3D18DD37691: removed
postsuper: Deleted: 1 message
postsuper: warning: invalid mail queue id: 38954D3768F!
postsuper: Deleted: 0 messages

Strip the status character and pass all IDs to one postsuper -d -, which reads IDs from standard input:

$ postqueue -p | awk '/MAILER-DAEMON/ {print $1}' | tr -d '*!' | postsuper -d -
postsuper: 38954D3768F: removed
postsuper: Deleted: 1 message

Postfix 3.1 and later also has postqueue -j, one JSON object per message, which avoids parsing the table. The empty sender appears there as "MAILER-DAEMON":

$ postqueue -j | jq -r 'select(.sender == "MAILER-DAEMON") | .queue_id' | postsuper -d -
postsuper: 5A6BDD376A4: removed
postsuper: 5CD10D376AA: removed
postsuper: Deleted: 2 messages

This is the version of the cleanup I keep in my Zimbra commands notes. Note that grep MAILER-DAEMON on the text output also matches a recipient line containing that word; the JSON filter only looks at the sender.

Tune the Postfix queue in Zimbra

Before you change anything from the Zimbra command line, check the current values. The defaults on Postfix 3.10, which match the values in the old post:

$ postconf maximal_queue_lifetime bounce_queue_lifetime queue_run_delay minimal_backoff_time maximal_backoff_time
maximal_queue_lifetime = 5d
bounce_queue_lifetime = 5d
queue_run_delay = 300s
minimal_backoff_time = 300s
maximal_backoff_time = 4000s

The old post set maximal_queue_lifetime=15m. Per the postconf(5) manual, a message is "undeliverable" once a temporary error has kept it in the queue for that long, so a receiving server that is down for 20 minutes makes your users' mail bounce. Use a short lifetime only on a test server. Also, bounces have their own limit, which the old post did not change:

$ postconf -e maximal_queue_lifetime=15m; postconf maximal_queue_lifetime bounce_queue_lifetime
maximal_queue_lifetime = 15m
bounce_queue_lifetime = 5d

For retries, postconf(5) says queue_run_delay "should be set less than or equal to $minimal_backoff_time", and maximal_backoff_time should be at least minimal_backoff_time. Setting both to 2000s, as in the old post, keeps that order and means fewer retries:

$ postconf -e queue_run_delay=2000s minimal_backoff_time=2000s; postfix reload; postconf queue_run_delay minimal_backoff_time maximal_backoff_time
postfix/postlog: refreshing the Postfix mail system
queue_run_delay = 2000s
minimal_backoff_time = 2000s
maximal_backoff_time = 4000s

On Zimbra there is one more rule. The Administrator's Guide warns that "changes made to postfix configuration files will be overwritten with every upgrade" and asks you to use Zimbra parameters where they exist. For the bounce lifetime it gives zmlocalconfig -e bounce_queue_lifetime={#}. Write down every postconf -e and every other Zimbra command line change you make on an MTA so you can apply it again after an upgrade.

Summary of the Zimbra command line fixes

  • LDAP lookups: use -W instead of -w password, and zmprov ga for single accounts.
  • SMTP connection count: netstat -nplt only shows listeners; use ss -Htn state established '( sport = :25 )'.
  • Queue cleanup: strip !/* or use postqueue -j with jq, and feed IDs to postsuper -d -.
  • Queue lifetime: 15 minutes bounces real mail; keep days on production and remember bounce_queue_lifetime.
  • Any Postfix change on Zimbra: prefer Zimbra parameters, and document the rest.

Keep these Zimbra commands in a runbook and test them on a non-production server first. Every Postfix parameter above is described in the postconf(5) manual, and the Zimbra side in the Zimbra Administrator's Guide.

Comments

Popular posts from this blog

Linux Desktop Frozen? 5 Proven Fixes Before a Hard Reboot

Minecraft Bedrock on Linux: 4 Proven Ways to Play in 2026

DXVK in Wine on Linux: 7 Easy Setup Steps, Tested