SMTP testing automation

I know there are scripts out there that does full-blown SMTP testing. I've used smtp-sink and smtp-source in Postfix for this purpose:

$ smtp-source -s 100 -m 100 -f [email protected] -t [email protected] server.address:25


So this was what I recommended to a friend, a Unix engineer in Singapore. But she had a different requirement: she has to establish an SMTP connection through telnet to a remote server, and send a template mail to thousands of recipients. The telnet session goes something like:


[user@host ~]$ telnet remote.host 25
Trying 123.456.789.10...
Connected to remotehost.remotedomain (123.456.789.10).
Escape character is '^]'.
220 mail.remote.host ESMTP Postfix
EHLO some.domain
250-mail.remote.host
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250 8BITMIME
MAIL FROM:[email protected]
250 Ok
RCPT TO:[email protected]
250 Ok
DATA
354 End data with.
Subject: This is a test
From: Sender

This is only a test.
.
250 Ok: queued as D81D7FA927
QUIT
221 Bye
Connection closed by foreign host.
[user@host ~]$


With thousands of recipients (no, her employer is not a spammer), this can be quite tedious. I thought of using an alias file at first, but the requirement was SMTP through telnet. So I told her to do the following:


  1. Create a recipients file, /tmp/recipients:

    [email protected]
    [email protected]
    ...
    [email protected]

  2. Create a message file, /tmp/message:

    Subject: This is a test
    From: Sender

    This is only a test.

  3. Create a script, smtp-telnet.sh:

    #!/bin/bash

    [email protected]

    (echo "HELO some.domain";
    sleep 1;
    echo "MAIL FROM:" $SENDER;
    sleep 1;
    for i in `cat /tmp/recipients`; do
    echo "RCPT TO:" $i;
    sleep 1;
    done;
    echo "DATA";
    sleep 1;
    cat /tmp/message;
    sleep 1;
    echo ".";
    sleep 1;
    echo "QUIT") | telnet remote.host 25

  4. Do a chmod 744 smtp-telnet.sh and run the script:
    $ ./smtp-telnet.sh


The sleep parameter can be increased to compensate for delays. I tested it on 50 users in my local test environment, and it worked for me.

Comments

Popular posts from this blog

Pull files off Android phone