Articles in this section

How to list all forwarding destinations, mailing lists with their members and email aliases for a domain in Plesk via CLI?

kb: how-to

Question

How to list all forwarding destinations, mailing lists with their members and email aliases for a domain in Plesk via CLI?

Answer

Note: Make sure to replace example.com with the actual domain name when executing any of the below commands.

  1. Connect to a Plesk server via SSH.
  2. Execute the following commands:
    To list all Email forwarders:

    # plesk db "select concat(m.mail_name,'@',d.name) as 'mailbox', mr.address as 'forwarding destination' from mail m left join domains d on m.dom_id=d.id left join mail_redir mr on m.id=mr.mn_id where d.name='example.com' and m.mail_group='true'"

    To list all Mailing lists:

    # domain='example.com';plesk db -Ne "select ml.name from MailLists ml left join domains d on ml.dom_id=d.id where d.name='$domain'"|while read i; do echo "Members of $i@$domain:";/usr/lib/mailman/bin/list_members $i;done

    To list all Email aliases:

    # plesk db "select concat(m.mail_name,'@',d.name) as 'mailbox', concat(ma.alias,'@',d.name) as 'alias' from mail m left join domains d on m.dom_id=d.id left join mail_aliases ma on m.id=ma.mn_id where d.name='example.com' and ma.alias is not NULL"

Was this article helpful?

Comments

1 comment
Date Votes
  • In case this helps anyone, here is my query that shows all email accounts for a domain, a column for if it's a mailbox or not, any aliases, any forwards, grouped by mail account.  I think it's accurate, but of course, please verify it contains all the data you expect.  I don't see how to post as code here, so you may need to replace the html fancy quotes with normal quotes to use it, and of course, replace example.com with your domain.

    plesk db “select concat(m.mail_name,'@',d.name) as 'mailbox', m.postbox AS is_mailbox, GROUP_CONCAT(concat(ma.alias,'@',d.name)) as 'alias', GROUP_CONCAT(mr.address) as 'forwarding destination'  FROM mail m left join domains d on m.dom_id=d.id left join mail_aliases ma on m.id=ma.mn_id left join mail_redir mr on m.id=mr.mn_id where d.name='example.com' GROUP BY concat(m.mail_name,'@',d.name) order by m.mail_name asc”

    0

Please sign in to leave a comment.