forked from Tecnativa/docker-postfix-relay
/
sendmail_test
48 lines (38 loc) · 1.07 KB
/
sendmail_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
set -e
user=test
from_name='Test'
from_email=$1
to_name='Your name'
to_email=$2
file=/tmp/emailtest.eml
if [ -z "$from_email" ] || [ -z "$to_email" ]; then
echo "Usage: $(basename $0) <email_from> <email_to>"
exit 1
fi
echo -n "Preparing email ... "
cat > $file << EOL
Subject: Email test for $HOST.$DOMAIN
From: $from_name <$from_email>
To: $to_name <$to_email>
Content-Type: text/plain; charset=UTF-8
This is a test email for server $HOST.$DOMAIN.
You do not have to do anything, but remove it.
Thanks
EOL
echo "OK"
echo -n "Sending email using sendmail ... "
sendmail -f "$from_email" "$to_email" < $file
error=$?; if [ $error -ne 0 ]; then echo "ERROR: $error"; exit $error; fi
echo "OK"
echo -n "Waiting some seconds ... "
sleep 5
echo "OK"
echo "-----------------------------------------------------"
echo " Log"
echo "-----------------------------------------------------"
tail /var/log/syslog
echo "-----------------------------------------------------"
echo " Outgoing email queue"
echo "-----------------------------------------------------"
postqueue -p