Coredump
Work, play, and everything in-between [feed]

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 sender@domain.com -t recipient@domain.com 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:sender@this.domain
250 Ok
RCPT TO:recipient@another.domain
250 Ok
DATA
354 End data with<cr><lf>.<cr><lf>
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 ~]$</lf></cr></lf></cr>

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:
    recipient1@some.domain
    recipient2@another.domain
    ...
    recipientX@yet.another.domain
  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
     
    SENDER=sender@this.domain
     
    (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.

Read more:


No Comments Yet


Be the first to comment!

Leave a comment


« »