Created
May 15, 2011 11:08
-
-
Save ssm/973052 to your computer and use it in GitHub Desktop.
Shell function to test local system mail configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shell function to test mail delivery. | |
# Requirements: Linux, and "sendmail" somewhere in PATH | |
# Run "testmail <recipient>". This will return a single string, for | |
# which you can find in the mail log. | |
testmail () { | |
if [ -n "$1" ]; then | |
uuid=$(cat /proc/sys/kernel/random/uuid); | |
msgid_domain=$(hostname --fqdn); | |
sendmail -oi -t <<EOF | |
Subject: test - $uuid | |
Message-Id: <testmail.$uuid@$msgid_domain> | |
To: <$1> | |
Test mail with identifier $uuid | |
-- | |
Regards, | |
$LOGNAME | |
EOF | |
exitcode=$? | |
if [ "$exitcode" = 0 ]; | |
then | |
echo "$uuid" | |
else | |
echo "not sent" | |
fi | |
else | |
echo "Usage: testmail <rcpt>" | |
fi | |
return $exitcode | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment