Usually, I am using zmprov to get some information from account, domain, server, or global configuration. Now, I try to use zmsoap. Here are some examples
# Get mail queue
/opt/zimbra/bin/zmsoap -z GetMailQueueRequest/server @name=mtaserver.example.com queue @name=deferred @scan="1" @wait="600" query --json > /tmp/queuemail.json
Note: Change mtaserver.example.com with your Zimbra MTA server
# Get total mail queue by sender
echo "Total : $(jq '.server[].queue[].total' /tmp/queuemail.json)" && jq -r '.server[].queue[].qs[] | select(.type == "from") | .qsi[] | "\(.n) -> \(.t)"' /tmp/queuemail.json | sort -rn
Here are the results
Total : 21 11 -> [email protected] 10 -> [email protected]
# Remove mail queue based on sender
/opt/zimbra/bin/zmsoap -z MailQueueActionRequest/server @name=mtaserver.example.com queue @name=deferred action @op=delete @by=query query field @name=from match @[email protected]
Note: Change mtaserver.example.com with your Zimbra MTA server
# Get status service
/opt/zimbra/bin/zmsoap -z GetServiceStatusRequest/status --json| jq -r '.status[] | "\(.server) -> \(.service) -> \(._content)"'
/opt/zimbra/bin/zmsoap -z GetServiceStatusRequest/status --json| jq -r '.status[] | "\(.server) -> \(.service) -> \(if ._content == "0" then "stopped" else "running" end)"'
use map option
/opt/zimbra/bin/zmsoap -z GetServiceStatusRequest/status --json | jq -r '.status[] | { "0": "stopped", "1": "running" } as $map | "\(.server) -> \(.service) -> \($map[._content])"'
Here are the results
mail.example.com -> onlyoffice -> running mail.example.com -> memcached -> running mail.example.com -> zmconfigd -> running mail.example.com -> zimbra -> running mail.example.com -> logger -> running mail.example.com -> proxy -> running mail.example.com -> zimlet -> running mail.example.com -> license-daemon -> running mail.example.com -> convertd -> running mail.example.com -> mta -> running mail.example.com -> mailbox -> running mail.example.com -> service -> running mail.example.com -> ldap -> running mail.example.com -> opendkim -> running mail.example.com -> zimbraAdmin -> running
# Get ID user
/opt/zimbra/bin/zmsoap -z GetAccountInfoRequest/[email protected] @by=name --json | jq -r '.a[] | select(.n == "zimbraId") | ._content'
Here are the results
51fb1fa7-84c4-45dc-8e4d-086c3aceb7d3
# Change password user
/opt/zimbra/bin/zmsoap -z SetPasswordRequest @id=51fb1fa7-84c4-45dc-8e4d-086c3aceb7d3 @newPassword=Strongpassword
Note: the value of id is getting from “Get ID user”
Good luck 🙂