Skip to content

Instantly share code, notes, and snippets.

@richardjoo
Last active December 1, 2023 07:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save richardjoo/9bd73de71c74a8c777b7 to your computer and use it in GitHub Desktop.
Save richardjoo/9bd73de71c74a8c777b7 to your computer and use it in GitHub Desktop.
my most frequently used exim commandlines
  • Print a count of the messages in the queue:

    exim -bpc

  • How to resend frozen messages in exim4 queue

    exim -bp | grep frozen | awk '{print $3}' | xargs exim -v -M

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

    exim -bp

  • Information about all the messages on the queue:

    exim -bp | less

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

    exim -bp | exiqsumm

  • Print what Exim is doing right now:

    exiwhat

  • Remove frozen emails

    exim -bpr | grep frozen | awk '{print $3}' | xargs exim -Mrm

  • Force delivery of one message

    exim -M email-id

  • display emails with particular email address

    exiqgrep -i -f (MAIL ADDRESS HERE) | xargs exim -bpr

  • Remove emails with particular email address

    exiqgrep -i -f email_address_here | xargs exim -bpr | awk {'print $3'} | xargs exim -Mrm

  • How many Frozen mails on the queue

    exim -bpr | grep frozen | wc -l

  • View the log for the message.

    exim -Mvl messageID

  • View the body of the message.

    exim -Mvb messageID

  • View the header of the message

    exim -Mvh messageID

  • Remove message without sending any error message

    exim -Mrm messageID

  • Giveup and fail message to bounce the message to the Sender

    exim -Mg messageID

  • How many mails on the Queue?

    exim -bpr | grep "<" | wc -l

  • How to force sending the list from exim -bpr?

    exim -bpr | awk {'print $3'} | xargs exim -M

  • display messages which have been on the queue for a day or more:

    exiqgrep -o $((60*60*24))

  • To find the largest files on the queue

    exim -bpr | awk '/^.[0-9]/{if($2~/[MK]/){ if($2~/K/){u="K"; uf=1024} else {u="M"; uf=1024*1024}; num=uf*substr($2,0,index($2,u))}else{num=$2}; print $1 " " num " "$3" "$4" "$5" "$6" "$7" "$8}' | sort -k2nr | head

  • More simply, to display a count of emails larger than 20K:

    exipick -bp '$message_size > 20K'

  • To display a count of emails larger than 20K:

    exipick -bpc '$message_size > 20K'

  • How to print que status to file?

    exim -bp | exiqsumm > exim-status-date '+%Y-%m-%d-%H-%M-%S'.txt

  • how to generate exim report

    make it full report and save to HTML file with date stamp on it
      eximstats -html=exim-report-`date '+%Y-%m-%d-%H-%M-%S'`.html /var/log/exim4/mainlog
    
    make it simple report and save to the HTML file with date stamp on it
      eximstats -ne -nr -nt -html=exim-report-`date '+%Y-%m-%d-%H-%M-%S'`.html /var/log/exim4/mainlog
      eximstats -ne -nr -nt /var/log/exim4/mainlog
    
    make it full report to the screen
      eximstats /var/log/exim4/mainlog /var/log/exim4/mainlog.1
    
  • To copy a file from B to A while logged into B:

    scp /path/to/file username@a:/path/to/destination

  • To copy a file from B to A while logged into A:

    scp username@b:/path/to/file /path/to/destination

  • sending message from command line

    exim -v your_to_email_address
    FROM: from_email_address
    TO: to_email_address
    SUBJECT: test
    test
    
    CTRL+D
    CTRL+C
    
  • Test how exim will route a given address:

root@localhost# exim -bt alias@localdomain.com
user@thishost.com
<-- alias@localdomain.com
router = localuser, transport = local_delivery
root@localhost# exim -bt user@thishost.com
user@thishost.com
router = localuser, transport = local_delivery
root@localhost# exim -bt user@remotehost.com
router = lookuphost, transport = remote_smtp
host mail.remotehost.com [1.2.3.4] MX=0
  • Cron Jobs
# m h  dom mon dow   command
58   11 * * * sh /home/user-folder/exim-simple-report.sh
*/10  * * * * sh /home/user-folder/exim-status.sh
  • creating shell file for cron jobs
exim-simple-report.sh
#!/bin/sh
/usr/sbin/eximstats -ne -nr -nt -html=/home/user-folder/exim-report-`date '+%Y-%m-%d-%H-%M-%S'`.html /var/log/exim4/mainlog

exim-status.sh
#!/bin/sh
/usr/sbin/exim -bp | /usr/sbin/exiqsumm > /home/user-folder/exim-status.txt

make sure to replace "user-folder" to your home directory - for example, like /home/jdoe/
  • after create files, run
chmod +x exim-simple-report.sh
chmod +x exim-status.sh
echo 'git pull'
git pull
echo 'git status'
git status
echo 'git add . --all'
git add . --all
echo 'git status'
git status
echo 'git files checked / added / updated'
git commit -am 'files checked / added / updated'
echo 'git push'
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment