=Purpose=

This script is a quick and simple tool for testing login credentials for mail services. This can be used to confirm that authentication is working for various mail services on a server, and/or to test existing credentials provided by a client. Because this script uses remote connections using either [[telnet]], [[netcat]], or [[OpenSSL]], the script also utilizes the [[Expect]] utility for automating the task of running commands in a remote shell such as the above.

=The Script=

To use this script you should first create a bin directory in your user's home directory on your workstation. Then you should make sure that this bin directory is in your executable path if it’s not already. This will make is so you can run the script from anywhere in your terminal.

mkdir ~/bin/ wget -O ~/bin/emailtest.sh layer3.liquidweb.com/scripts/mcunningham/emailtest.sh chmod +x ~/bin/emailtest.sh =Example Output and Usage= ==Help Output==

 Usage: emailtest.sh [options] [hostname] [email-address] [password]

    -i | --imap ..... Test IMAP
    -p | --pop3 ..... Test POP3
    -s | --smtp ..... Test SMTP
    -S | --ssl ...... Use SSL connection
    -T | --tls ...... Use TLS connection
    -P | --port ..... Set alternate port
    -v | --verbose .. Show full SSL Cert output

 Examples:
    SMTP with TLS
    emailtest.sh -s -T [host] [email] [pass]

    IMAP with SSL
    emailtest.sh -i -S [host] [email] [pass]

    POP3 with SSL
    emailtest.sh -p -S [host] [email] [pass]

    SMTP with alternate port
    emailtest.sh -s -P 26 [host] [email] [pass]

==Basic Usage==

The basic usage of this script requires what service your logging into, what kind of encryption the connection should use, if any. After those options there are three positional parameters: hostname, username, and password. Those aruments must go in that order, to be used as expected. If you do not specify the hostname, username, or password at the command line, the script will prompt you to input those manually.

emailtest.sh [Method: --imap|--pop|--smtp] [Encryption: --ssl|--tls] [--port <##>] [hostname] [email-address] [password]
===IMAP-SSL===
emailtest.sh --imap --ssl mail.robotzombies.net mcunningham@robotzombies.net
Server Temp Key: DH, 1024 bits

spawn openssl s_client -crlf -servername robotzombies.net -connect mail.robotzombies.net:993 -quiet
depth=3 C = SE, O = AddTrust AB, OU = AddTrust External TTP Network, CN = AddTrust External CA Root
verify return:1
depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
verify return:1
depth=1 C = US, ST = TX, L = Houston, O = "cPanel, Inc.", CN = "cPanel, Inc. Certification Authority"
verify return:1
depth=0 CN = robotzombies.net
verify return:1
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE NAMESPACE AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
tag LOGIN mcunningham@robotzombies.net ..PASSWORDREMOVED..
tag OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE NAMESPACE NOTIFY SPECIAL-USE COMPRESS=DEFLATE QUOTA] Logged in
tag SELECT INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft nonjunk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft nonjunk \*)] Flags permitted.
* 93 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1456996671] UIDs valid
* OK [UIDNEXT 94] Predicted next UID
* OK [HIGHESTMODSEQ 122] Highest
tag OK [READ-WRITE] Select completed (0.000 + 0.000 secs).
tag FETCH 1 BODY[]
tag LOGOUT
* 1 FETCH (BODY[] {1063}

..Email body removed..

tag OK Fetch completed (0.002 + 0.000 + 0.001 secs).
* BYE Logging out
tag OK Logout completed (0.000 + 0.000 secs).
===SMTP-TLS===
emailtest.sh --smtp --tls mail.robotzombies.net mcunningham@robotzombies.net
spawn openssl s_client -starttls smtp -crlf -servername robotzombies.net -connect mail.robotzombies.net:587 -quiet
depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
verify return:1
depth=1 C = US, ST = TX, L = Houston, O = "cPanel, Inc.", CN = "cPanel, Inc. Certification Authority"
verify return:1
depth=0 CN = robotzombies.net
verify return:1
250 HELP
EHLO mcunningham.wks.liquidweb.com
250-host.axeblade.net Hello mcunningham.wks.liquidweb.com [10.30.4.98]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250 HELP
AUTH LOGIN
334 VXNlcm5hbWU6
bWN1bm5pbmdoYW1Acm9ib3R6b21iaWVzLm5ldA==
334 UGFzc3dvcmQ6
UEFTU1dPUkRSRU1PVkVE
235 Authentication succeeded
QUIT
221 host.axeblade.net closing connection
=Bugs=

When utilizing SSL or TLS encryption on the connection the encryption needs to be specified after the authentication type (ie. --imap -ssl, or --smtp --tls)

Please submit any bugs and/or feature requests to: [mailto:mcunningham@liquidweb.com mcunningham]

[[Category:Monitoring]] [[Category:Migrations]] [[Category:Support]]