Blame tests/p_sendmail/20_sendmail_mta.sh

Christoph Galuschka 0c087a
#!/bin/sh
Christoph Galuschka 0c087a
# Author: Christoph Galuschka <christoph.galuschka@chello.at>
Christoph Galuschka 0c087a
Christoph Galuschka 0c087a
t_Log "Running $0 - sendmail can accept and deliver local email."
40b4c8
if [ "$CONTAINERTEST" -eq "1" ]; then
40b4c8
    t_Log "Running in container -> SKIP"
40b4c8
    exit 0
40b4c8
fi
baf472
ret_val=1
Christoph Galuschka 0c087a
Christoph Galuschka 0c087a
# send mail to localhost
957f65
mail=$(echo -e "helo localhost\nmail from: root@localhost\nrcpt to: root@localhost\ndata\nt_functional test\n.\nquit\n" | nc -w 5 127.0.0.1 25 | grep accepted)
3bb82f
MTA_ACCEPT=$?
3bb82f
if [ $MTA_ACCEPT == 0 ]
Christoph Galuschka 0c087a
  then
Christoph Galuschka 0c087a
  t_Log 'Mail has been queued successfully'
Christoph Galuschka 0c087a
fi
Christoph Galuschka 0c087a
Christoph Galuschka 0c087a
sleep 1
834d5e
834d5e
if [ "$centos_ver" -eq "8" ]; then
834d5e
  t_Log "Dumping journalctl to /var/log/maillog"
834d5e
  journalctl -u sendmail >> /var/log/maillog
834d5e
fi
1dfe80
regex='250\ 2\.0\.0\ ([0-9A-Za-z]*)\ Message\ accepted\ for\ delivery'
c6cf39
if [[ $mail =~ $regex ]]
Christoph Galuschka 0c087a
  then
1dfe80
  egrep -q "${BASH_REMATCH[1]}\:.*stat\=Sent" /var/log/maillog
c6cf39
  DELIVERED=$?
Christoph Galuschka 0c087a
fi
Christoph Galuschka 0c087a
1dfe80
if ([ $MTA_ACCEPT == 0  ] && [ $DELIVERED == 0 ])
Christoph Galuschka 0c087a
  then
Christoph Galuschka 0c087a
  ret_val=0
c6cf39
  t_Log 'Mail has been delivered and removed from queue.'
Christoph Galuschka 0c087a
fi
Christoph Galuschka 0c087a
Christoph Galuschka 0c087a
t_CheckExitStatus $ret_val