SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Thread: Testing e-mail

  1. #1
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Testing e-mail

    Hi.

    I didn't want to announce this until we had used it in real world tests. We now have.

    Fakemail:
    http://www.lastcraft.com/fakemail.php
    http://sourceforge.net/projects/fakemail

    It's a tool to test e-mail systems. It's basically a fake MTA that traps outgoing mails on a port of your choosing and then dumps them to the file system. You would probably use it in conjunction with an automated test suite, and I give an example of this at the bottom of the page. The catch is that you have to be able to either tell you application to use a non-standard port, or you have to turn off your SMTP gateway while you run the tests. We tend to go for the former.

    In case you don't want to follow the link, here is how you start fakemail...
    Code:
    fakemail --host=localhost --port=10025 --path=temp --background
    It runs as a daemon process and returns it's process ID so that you can kill it. Captured mails would be saved into the "temp" directory in this case.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I saw that on your site a day or two ago. You never cease to amaze by coming up with some very useful tools. Great job. I already have plans for using it. Thanks.
    Erh

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this would be Unix/Linux only, i presume? I had thoughts of using it on Windows though...

  4. #4
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Pavel has got it running on Windows using the Cygwin Perl. We had some trouble with an earlier version running on ActiveState Perl because the dependent didn't seem to work the same. Personally I am Linux based, so investigation is difficult for me.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is why i have to figure out how to install linux on my usb harddrive...then i could test my email scripts with fakemail!

    Good job, seriously. This will be insanely useful especially when combined with SimpleTest.

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    with my kids
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, this is great timing for me. i just rewrote a mailing list manager which this will be perfect for. we send up to 10000 emails a day, and in the past, whenever changes were made, we would send out a "Please excuse our upgrade message" email to a couple thousand unlucky recipients in order to test it fully.

    sourceforge won't let me sign up for the mailing list, so i'm posting here.

    first, a very minor issue. the documentation has a typo on invoking fakemail. the "path" argument in the little screenshots are missing the "--".
    fakemail --host=localhost --port=10025 path=.
    second, i'm trying to get it running on windows (i do have cygwin installed, so i could fall back to that). when you say
    We had some trouble with an earlier version running on ActiveState Perl because the dependent didn't seem to work the same.
    what exactly is "the dependent"? do you have any other insights?
    right now, fakemail starts up fine:
    C:\dev\work\fakemail>perl fakemail --host=localhost --port=10025 --path=.
    Starting fakemail
    Listening on port 10025
    so i open another terminal and when i telnet in to localhost:10025 i get (in the first (fakemail) terminal)
    Starting Request
    and in the second terminal i get
    220 55189-3CXNS11 SMTP Net::Server::Mail (Perl) Service ready
    unfortunately, when i try to HELO, i get an error on each character:
    H500 Syntax error: unrecognized command
    E500 Syntax error: unrecognized command
    L500 Syntax error: unrecognized command
    O500 Syntax error: unrecognized command
    i've tracked down the culprit to a problem in how Mail reads from the socket in Windows. as it is, it's only reading the first character (obviously). i've sort of got a hack working to make it read more, but i don't have the Perl-fu to make a full go of it.

    thanks again.

  7. #7
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by josheli
    sourceforge won't let me sign up for the mailing list, so i'm posting here.
    Oh ? Is this a general problem, or just this list?

    Quote Originally Posted by josheli
    first, a very minor issue.
    Yeah, I've fixed this on a later build.

    Quote Originally Posted by josheli
    i've tracked down the culprit to a problem in how Mail reads from the socket in Windows. as it is, it's only reading the first character (obviously). i've sort of got a hack working to make it read more, but i don't have the Perl-fu to make a full go of it.
    This is what I meant by the dependent, the SMTP library which I don't actually understand. You need to talk to Pavel (the Limb guy) about this. I really am no good at all with Windows.

    I'll have a go at setting up a Windows environment and see if I can get it to work, but I doubt I will be able to give advice whether it works, fails the same as yours or fails differently . What was your hack?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  8. #8
    Resident Java Hater
    Join Date
    Jul 2004
    Location
    Gerodieville Central, UK
    Posts
    446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by petesmc
    This is why i have to figure out how to install linux on my usb harddrive...then i could test my email scripts with fakemail!

    Good job, seriously. This will be insanely useful especially when combined with SimpleTest.
    Just nab a copy of cygwin, or download a "trial" of VMware to slap linux on to. That way you can still use Windows if you aren't a Linux regular

  9. #9
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    with my kids
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this a general problem, or just this list?
    a general problem.
    What was your hack?
    after much fussing around with various hacks, the following seems to work.
    --- c:\.cpan\build\Net-Server-Mail-0.12\lib\Net\Server\Mail.pm 2005-03-03 07:03:51.000000000 -0600
    +++ c:\Perl\lib\Net\Server\Mail.pm 2005-05-11 13:27:37.359375000 -0500
    @@ -480,11 +480,15 @@
    {
    # see how much data is available to read
    my $size = pack("L",0);
    - ioctl($in, 1074030207, $size);
    - $size = unpack("L", $size);
    + #ioctl($in, 1074030207, $size);
    + #$size = unpack("L", $size);

    # read the data and put it in the $_ variable
    - read($in, $_, $size);
    + #read($in, $_, $size);
    +
    + $in->ioctl(1074030207, $size);
    + $size = unpack("L", $size);
    + $in->read($_, $size);
    }
    else
    {

  10. #10
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    with my kids
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh, and i don't know if this is a bug, since it should be up to the client to check the validity of an email address, and the fakemail "validate_recipient" sub isn't really implemented, but if the address isn't a valid file name, fakemail still tries to write a file (and claims that it was successful):
    Incoming mail
    Capturing mail to <foo"@b;a.r.com>
    print() on closed filehandle FILE at fakemail line 98, <GEN4> line 21.
    Mail to <foo"@b;a.r.com> saved
    Incoming mail dispatched
    Request done

  11. #11
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Ok, your hack is in the dependent mail package. If I pass this on it will just create confusion. Could you mail the CPAN author with your fix? Would you lke to join the fakemail project ?

    Quote Originally Posted by josheli
    oh, and i don't know if this is a bug, since it should be up to the client to check the validity of an email address, and the fakemail "validate_recipient" sub isn't really implemented, but if the address isn't a valid file name, fakemail still tries to write a file (and claims that it was successful):
    Good point. For the next beta we'll try to add some coercion to a valid file name. What was the mail address you were trying to write out?

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  12. #12
    SitePoint Zealot
    Join Date
    Dec 2003
    Location
    with my kids
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you mail the CPAN author with your fix?
    I have no inkling as to the correctness of this change, or what else it might break, but I will see what he says.
    Would you lke to join the fakemail project ?
    Thanks for the offer, but I like to contribute from the sidelines.
    What was the mail address you were trying to write out?
    the one in my post above: foo"@b;a.r.com. but any invalid filename will do.

    also, i don't know if this an effect of my changes to the Mail.pm file, or part of the whole Windows thing, and i haven't figured out all the correct behaviors of this, but setting SMTPKeepAlive = TRUE using PHPMailer as the client leaves fakemail hanging (actually the Mail.pm code in a loop):

    the phpmailer doc says
    /**
    * Prevents the SMTP connection from being closed after each mail
    * sending. If this is set to true then to close the connection
    * requires an explicit call to SmtpClose().
    * @var bool
    */
    var $SMTPKeepAlive = false;
    i guess this is the right thing to do? but it means that you can't use SMTPKeepAlive and send more than 1 email through fakemail. basically if SMTPKeepAlive is TRUE, then PHPMailer sends a RSET instead of closing the connection, but fakemail/Mail doesn't seem to respond correctly and just waits, never returns...
    Starting request
    Incoming mail
    Capturing mail to <test@test>
    Mail to <test@test> saved
    Incoming mail dispatched
    i'll need to look more closely though.

  13. #13
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Hm...this is going to need a major investigation/debugging session isn't it? i don't have time right now, or even the coming months, so I think fakemail will be in beta for wuite a while.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  14. #14
    SitePoint Addict pachanga's Avatar
    Join Date
    Mar 2004
    Location
    Russia, Penza
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    Pavel has got it running on Windows using the Cygwin Perl. We had some trouble with an earlier version running on ActiveState Perl because the dependent didn't seem to work the same.
    That's correct, fakemail works fine with Cygwin Perl and Active State Perl crashed saying something about posix forking stuff not implemented for windows...

    Just make sure you have the path to the Cygwin bin directory placed first in the system Path env. variable(this is probably not really related to running fakemail on windows yet it makes sense if you want to actively use nice Cygwin stuff).

  15. #15
    SitePoint Addict pachanga's Avatar
    Join Date
    Mar 2004
    Location
    Russia, Penza
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW, there's also not documented(yet tested ) php wrapper for fakemail - FakeMailDaemon class which incapsulates server stop, start and some utility routines.

    It's pretty useful even being in the very beta state. You can browse it along with tests in fakemail CVS.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •