Grep Exim Email Transaction with Bash

While email transport having problem, the first we look for is the email log file, to check incoming and outgoing email transaction, to see was the email sent to the recipient or whether did the sender’s email it delivered to our email server.

I like exim log file provide the transport when an email is coming in or out from the server. I have written a simple script to grep sender/recipient email address and analysis the email transaction.


#!/usr/local/bin/bash

E_WRONGARGS=85  # Non-numerical argument (bad argument format).

    # Using Case or
    case "$1" in
    ""          ) echo "Usage: `basename $0`  "; exit $E_WRONGARGS;;
    *           ) lines=$1;;
    esac

    # Using If Eles for simple validation
    if [ ! -f "$2" ]
    then
           echo "Log File not Exist";
           exit;
    fi

LOGFILE=$2
LOGKEYWORD=$1

email_ids=($(grep $LOGKEYWORD $LOGFILE | awk '{print $3}' | uniq))

for email_id in ${email_ids[@]}
do
        grep $email_id $LOGFILE
        echo -e
        echo -e
done

exit 0

I’ve not receiving email from linkedin newsletter lately, lets try to check email log in my server yesterday.


./exim-log linkedin /var/log/exim/mainlog

2009-07-01 23:39:40 1M8cGq-000FKz-Il <= *.linkedin.com H=(xxxxx) [xxx.xxx.xxx.xxx]
2009-07-01 23:39:40 1M8cGq-000FKz-Il => /mail/spam-2009-05-25  T=address_file
2009-07-01 23:39:40 1M8cGq-000FKz-Il Completed


Oppsss… Email was classified as Spam! Ok, something is wrong with my exim spam filter.

Related posts:

  1. Force Email Delivery on Exim Hundred emails are queuing on your mail relay server, and...
  2. Exim: Restrict Authenticated Outgoing Email with Sender Domain Most of the outgoing SMTP server allowed the user to...
  3. Exim, Recipient Verify on Relay and Mail Server How many of you got dictionary/ratware attack on your mail...
  4. Backup and Archive Incoming Email with Exim Loitering around Google and finding a way to archive/backup incoming...
  5. exim, playing with mail queue in server there are over thousand emails queue in our mail server,...
  6. Enable SMTP Port 587 on Exim Most of the ISP block port 25 for outgoing SMTP....
  7. exim: rejected EHLO, syntactically invalid argument If you email having problem with rejected EHLO or HELO,...
  8. Bash: How to Echo Tab and Newline While printing out result in bash, sometime we need to...
  9. Exim, refused: too many connections One of our mailserver having problem last week. It’s caused...
  10. Arrays in Bash Arrays is useful when it comes to data processing. Using...

Leave a Reply