Skip to content

Instantly share code, notes, and snippets.

@ssm
Created May 15, 2011 11:08
Show Gist options
  • Save ssm/973052 to your computer and use it in GitHub Desktop.
Save ssm/973052 to your computer and use it in GitHub Desktop.
Shell function to test local system mail configuration
# 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