Skip to content

Instantly share code, notes, and snippets.

@tokudan
Created March 12, 2018 20:25
Show Gist options
  • Save tokudan/7a91cdfffd3b792a998d4aaa7337d949 to your computer and use it in GitHub Desktop.
Save tokudan/7a91cdfffd3b792a998d4aaa7337d949 to your computer and use it in GitHub Desktop.
#!/run/current-system/sw/bin/bash
write_line() {
sleep 0.1${RANDOM}
echo "-> $*"
echo "$*" >&99
sleep 0.1${RANDOM}
}
get_last_reply() {
sleep 1
tail -1 ${MAILTMP}
}
make_mail() {
FROM="$1"
TO="$2"
SUBJECT="$3"
echo "Message-Id: <${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM}@${HOSTNAME}>"
echo "From: <${FROM}>"
echo "To: <${TO}>"
echo "Date: $(LANG=C date "+%a, %d %b %Y %H:%M:%S %z")"
echo "Subject: ${SUBJECT}"
echo ''
echo 'Hallo Nina,'
echo ''
echo 'wie geht es dir?'
echo ''
echo 'Gruß'
echo 'Daniel'
}
test_mail() {
echo '####################### Next test'
echo "########### FROM: ${FROM}"
echo "########### TO: ${TO}"
echo "########### SUBJECT: ${SUBJECT}"
# Open the connection
exec 99<>/dev/tcp/${SERVER}/smtp
sed -e 's_^_<- _' <&99 &
SEDPID=$!
write_line "EHLO ${HOSTNAME}"
write_line "MAIL FROM: <${FROM}>"
write_line "RCPT TO: <${TO}>"
write_line 'DATA'
write_line "$(make_mail ${FROM} ${TO} "${SUBJECT}")"
write_line '.'
write_line 'QUIT'
wait ${SEDPID}
# Close the fd
exec 99<&-
}
if [ $# -gt 0 ]; then
SERVER="$1"
FROM="$2"
TO="$3"
SUBJECT="$4"
test_mail
exit
fi
$0 myserver.mydomain.com valid_outside_email@example.org validuser@mydomain.com "Test 1: regular delivery"
echo '####################### Expected result: 250 2.0.0 Ok: queued as'
echo
$0 myserver.mydomain.com valid_outside_email@example.org someone@mydomain.com "Test 2: unknown user reject"
echo '####################### Expected result: 550 5.1.1 <someone@mydomain.com>: Recipient address rejected: User unknown in virtual mailbox table'
echo
$0 myserver.mydomain.com valid_outside_email@example.org root@myserver.mydomain.com "Test 3: local server users"
echo '####################### Expected result: 554 5.7.1 <root@myserver.mydomain.com>: Relay access denied'
echo
$0 myserver.mydomain.com valid_outside_email@example.org root@localhost "Test 4: localhost users"
echo '####################### Expected result: 554 5.7.1 <root@localhost>: Relay access denied'
echo
$0 myserver.mydomain.com valid_outside_email@example.org root@myserver.mydomain.com "Test 5: local users"
echo '####################### Expected result: 554 5.7.1 <root@myserver.mydomain.com>: Relay access denied'
echo
$0 myserver.mydomain.com valid_outside_email@example.org elsewhere@example.com "Test 6: relay access test"
echo '####################### Expected result: 554 5.7.1 <elsewhere@example.com>: Relay access denied'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment