Skip to content

Instantly share code, notes, and snippets.

@derak-kilgo
Last active May 18, 2023 21:36
Show Gist options
  • Save derak-kilgo/2ff1368574c40080b3ced472b3857b7f to your computer and use it in GitHub Desktop.
Save derak-kilgo/2ff1368574c40080b3ced472b3857b7f to your computer and use it in GitHub Desktop.
Test SMTP with telnet using bash.
#!/bin/bash
#
# Solution based on https://stackoverflow.com/a/11988455/119829
# Thank you balanv.
#
base_domain=test.example.com;
command -v telnet >/dev/null 2>&1 || { echo >&2 "I require telnet but it's not installed. Aborting."; exit 1; }
[ "$1" ] || { echo >&2 "arg 1 (domain/ip4) cannot be empty."; exit 1; }
[ "$2" ] || { echo >&2 "arg 2 (port) cannot be empty."; exit 1; }
echo "Sending test message from [ $base_domain ] to [ $1 $2 ] via telnet...\n";
telnet $1 $2 <<EOF
helo $1 $2
mail from:<no-reply@$base_domain>
rcpt to:<test_script@$base_domain>
data
From: developer@$base_domain
Subject: This is a test message.
This is a test message from the linux command line. If you recieve this message then your SMTP server is configured correctly.
This tool only works with unencrypted connects.
.
quit
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment