You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.3 KiB
64 lines
1.3 KiB
#!/bin/bash
|
|
|
|
function usage {
|
|
echo 'usage: <SERVER> [USERNAME PASSWORD]'
|
|
exit 1
|
|
}
|
|
|
|
function connect_server {
|
|
timeout 2 openssl s_client -starttls smtp -connect "$server:587" -ign_eof 2>/dev/null <<EOF
|
|
quit
|
|
EOF
|
|
}
|
|
|
|
function auth_server {
|
|
base64=$(echo -ne "\0$username\0$password" | base64)
|
|
openssl s_client -starttls smtp -connect "$server:587" -ign_eof 2>/dev/null <<EOF
|
|
ehlo .
|
|
auth plain $base64
|
|
quit
|
|
EOF
|
|
}
|
|
|
|
function check_smtp_connection {
|
|
echo -n "check smtp server <$server> port 587 ... "
|
|
set +e
|
|
if connect_server | grep -q CONNECTED; then
|
|
echo SUCCESSFUL CONNECTION
|
|
else
|
|
echo wrong server connection! && exit 1
|
|
fi
|
|
}
|
|
|
|
function check_smtp_auth {
|
|
echo -n "check smtp authentication <$server> port 587 username=<$username> ... "
|
|
set +e
|
|
output=$(auth_server)
|
|
if echo "$output" | grep -q CONNECTED; then
|
|
if echo "$output" | grep -q "Authentication successful"; then
|
|
echo SUCCESSFUL AUTHENTICATION
|
|
else
|
|
echo wrong username or password! && exit 2
|
|
fi
|
|
else
|
|
echo wrong server connection! && exit 1
|
|
fi
|
|
set -e
|
|
}
|
|
|
|
### MAIN
|
|
|
|
set -Eeuo pipefail
|
|
|
|
server=${1:-}
|
|
username=${2:-}
|
|
password=${3:-}
|
|
|
|
[[ -z "$server" ]] && usage
|
|
|
|
if [[ -z "$username" ]]; then
|
|
check_smtp_connection
|
|
else
|
|
[[ -z "$password" ]] && usage
|
|
check_smtp_auth
|
|
fi
|