How to search through queued email by content

grep -rl /var/spool/exim/input/* | grep -oP '[^/\n]+$' | cut -b1-16  | xargs exim -Mrm

Explanation by part

  1. grep -rl /var/spool/exim/input/*

    Search for in all queued messagesn and returns a list of file paths.
  2. grep -oP '[^/\n]+$’ 

    Find the last part of the path, i.e., the filename
  3. cut -b1-16 

    The filename’s byte 1 through 16 constitutes the exim message ID.
  4. xargs exim -Mrm 

    Pipe the message ID to exim’s “delete from queue” function.

    Warning! Add this only if you want to delete the matching messages.