30 Handy Commands to Manage Exim Mail Server

June 30, 2014 | By
| 1 Reply More

Exim is a message transfer agent (MTA) for use on Unix systems connected to the Internet. It is freely available under the terms of the GNU General Public Licence. In style it is similar to Smail 3, but its facilities are more general. There is a great deal of flexibility in the way mail can be routed, and there are extensive facilities for checking incoming mail. Exim can be installed in place of Sendmail, although the configuration of Exim is quite different.

We can easily manage exim via command line.We can easily remove mailqueues, If any particular user sending large number of emails we can easily find that account and remove it.

1. To get a count of messages in the queue

exim -bpc

2. Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient)

exim -bp

exim 1

3. Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):

exim -bp | exiqsumm

4. Print what Exim is doing right now:

exiwhat

exim commands

5. Run a pretend SMTP transaction from the command line, as if it were coming from the given IP address. This will display Exim's checks, ACLs, and filters as they are applied. The message will NOT actually be delivered.

exim -bh 192.168.11.22

6. Display all of Exim's configuration settings:

exim -bP

Searching the queue with exiqgrep

Exim includes a utility that is quite nice for grepping through the queue, called exiqgrep. If you're not using this, and if you're not familiar with the various flags it uses, you're probably doing things the hard way, like piping `exim -bp` into awk, grep, cut, or `wc -l`. Don't make life harder than it already is.
First, various flags that control what messages are matched. These can be combined to come up with a very particular search.

7. Use -f to search the queue for messages from a specific sender:

exiqgrep -f [luser]@domain

8. Use -r to search the queue for messages for a specific recipient/domain:

exiqgrep -r [luser]@domain

9. Use -o to print messages older than the specified number of seconds. For example, messages older than 1 day:

exiqgrep -o 86400 [...]

10. Use -y to print messages that are younger than the specified number of seconds. For example, messages less than an hour old:

exiqgrep -y 3600 [...]

11. Use -s to match the size of a message with a regex. For example, 700-799 bytes:

exiqgrep -s '^7..$' [...]

Use -z to match only frozen messages, or -x to match only unfrozen messages. There are also a few flags that control the display of the output.

12. Use -i to print just the message-id as a result of one of the above two searches:

exiqgrep -i [ -r | -f ] ...

13. Use -c to print a count of messages matching one of the above searches:

exiqgrep -c ...

14. Print just the message-id of the entire queue:

exiqgrep -i

Managing the queue

The main exim binary (/usr/sbin/exim) is used with various flags to make things happen to messages in the queue. Most of these require one or more message-IDs to be specified in the command line, which is where `exiqgrep -i` as described above really comes in handy.

15. Start a queue run

root@localhost# exim -q -v

16. Start a queue run for just local deliveries:

root@localhost# exim -ql -v

17. Remove a message from the queue:

root@localhost# exim -Mrm <message-id> [ <message-id> ... ]

18. Freeze a message:

root@localhost# exim -Mf <message-id> [ <message-id> ... ]

19. Throw a message:

root@localhost# exim -Mt <message-id> [ <message-id> ... ]

20. Deliver a message, whether it's frozen or not, whether the retry time has been reached or not:

root@localhost# exim -M <message-id> [ <message-id> ... ]

21. Deliver a message, but only if the retry time has been reached:

root@localhost# exim -Mc <message-id> [ <message-id> ... ]

22. Force a message to fail and bounce as "cancelled by administrator":

root@localhost# exim -Mg <message-id> [ <message-id> ... ]

23. Remove all frozen messages:

root@localhost# exiqgrep -z -i | xargs exim -Mrm

24. Remove all messages older than five days (86400 * 5 = 432000 seconds):

root@localhost# exiqgrep -o 432000 -i | xargs exim -Mrm

25. Freeze all queued mail from a given sender:

root@localhost# exiqgrep -i -f luser@example.tld | xargs exim -Mf

26. View a message's headers:

root@localhost# exim -Mvh <message-id>

27. View a message's body:

root@localhost# exim -Mvb <message-id>

28. View a message's logs:

root@localhost# exim -Mvl <message-id>

29. Add a recipient to a message:

root@localhost# exim -Mar <message-id> <address> [ <address> ... ]

30. Edit the sender of a message:

root@localhost# exim -Mes <message-id> <address>

 

Filed Under : LINUX HOWTO, MAIL SERVER

Free Linux Ebook to Download

Comments (1)

Trackback URL | Comments RSS Feed

  1. RoseHosting says:

    Nice list, here is another handy command which will remove all messages from the queue:


    exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | sh

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.