Created
July 26, 2012 10:21
-
-
Save abdallah/3181372 to your computer and use it in GitHub Desktop.
Simple SMTP tester script
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
import smtplib | |
import argparse | |
import sys | |
parser = argparse.ArgumentParser(description='SMTP Tester', add_help=True) | |
parser.add_argument('-s', '--server', dest='server', action='store', | |
help='Server Name or IP') | |
parser.add_argument('-u', '--username', dest='username', action='store', | |
help='username - try with and without the @') | |
parser.add_argument('-p', '--password', dest='password', action='store', | |
help='password') | |
parser.add_argument('-f', '--from', dest='sender', action='store', | |
help='sender', default='smtptester@example.com') | |
parser.add_argument('-t', '--to', dest='to', action='store', | |
help='to', default='support@example.com') | |
parser.add_argument('--port', dest='port', action='store', | |
help='port (default=25)', default=25, type=int) | |
parser.add_argument('-v', dest='verbose', action='store_true', default=True) | |
args = parser.parse_args() | |
if not (args.server and args.username and args.password): | |
parser.print_help() | |
sys.exit(2) | |
server = smtplib.SMTP(args.server) | |
server.set_debuglevel(args.verbose) | |
server.ehlo() | |
server.login(args.username, args.password) | |
header = 'To: %s\nFrom: %s\nSubject: Testing SMTP\n' % (args.sender, args.to) | |
print header | |
msg = header + '\n this is a test msg, please reply to [%s] \n\n' % args.sender | |
server.sendmail(args.sender, args.to, msg) | |
print 'message sent!' | |
server.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment