Skip to content

Instantly share code, notes, and snippets.

@sstelfox
Created March 31, 2014 01:57
Show Gist options
  • Save sstelfox/9883715 to your computer and use it in GitHub Desktop.
Save sstelfox/9883715 to your computer and use it in GitHub Desktop.
Quick little script for testing whether or not a mail server is setup correctly.
#!/bin/bash
SMTP_SERVER='mail.example.tld'
EMAIL_FROM="$(whoami)@$(hostname)"
EMAIL_DESTINATION='[email protected]'
cat << EOM | nc -C ${SMTP_SERVER} 25
EHLO $(hostname)
MAIL FROM: ${EMAIL_FROM}
RCPT TO: ${EMAIL_DESTINATION}
DATA
From: $(grep -P "^$(whoami):" /etc/passwd | cut -f5 -d:) <${EMAIL_FROM}>
To: <${EMAIL_DESTINATION}>
Date: $(date +"%a, %d %b %Y %H:%M:%S %z (%Z)")
Subject: A Simple Test Message
This is a message for testing whether a mail server is setup correctly or not.
.
QUIT
EOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment