Euclid has asked for the wisdom of the Perl Monks concerning the following question:

I would like to simulate an SMTP server for the purposes of testing our product. This will allow us to verify that an email message was sent, as well as being able to verify the contents of the email message, for testing purposes.

We use the Test::More module for writing automated tests.

I would like to be able to setup a machine that simulates the SMTP server. The machine name could then be specified as the mail server in our product, instead of using a real mail server.

The script will listen on port 25, pretending to be a mail server by conversing in accordance with the SMTP protocol. The script should save the data received to the local file system for later inspection.

Replies are listed 'Best First'.
Re: Testing email send
by tachyon (Chancellor) on Oct 08, 2004 at 05:33 UTC
Re: Testing email send and Test::MockObject
by pernod (Chaplain) on Oct 08, 2004 at 07:57 UTC

    Another alternative is using chromatic's Test::MockObject to simulate the mail server. Mocking allows you to unit test your mail generating component independently from the mail server, and you will be able to trap the output of your code to verify the contents of your mail.

    This will not be enough, though, as you will need to test the component in combination with the mail server too. The unit tests will verify the interfaces between the two. I don't think mocking is the complete solution to your problem, but it will get you closer to your goal.

    Good luck!

    pernod
    --
    Mischief. Mayhem. Soap.

    Update: Fixed som typos

Re: Testing email send
by hsinclai (Deacon) on Oct 08, 2004 at 02:39 UTC
    If your product is real, and it depends on interacting with external SMTP servers, then you should be testing it with real SMTP servers, like Exchange, sendmail, qmail, postfix, exim. Yes you could write something in Perl but why not use the real thing and do a real test.

    This will allow us to verify ...
    I would think that you need to verify that your app is constructing messages in a compliant fashion and transacting SMTP properly when pointed at differently configured daemons.

Re: Testing email send
by doowah2004 (Monk) on Oct 08, 2004 at 03:28 UTC
    You might try qpstmpd, I am sure that you could easily modify this to save the data instead of sending it out.

    Just a thought.

    Cameron
Re: Testing email send
by Father Jack (Initiate) on Oct 08, 2004 at 05:25 UTC
    Why not just mess with your sendmail.mc file so that it translates all the To: addresses to a local account?
Re: Testing email send
by TedPride (Priest) on Oct 08, 2004 at 06:16 UTC
    Just use a real mail server. I use EIMS Server Lite on my Mac, for instance...
A reply falls below the community's threshold of quality. You may see it by logging in.