#1
  1. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,230
    Rep Power
    593

    Debugging Net::SMTP


    I am trying to use Net::SMTP which is failing on the 'mail' method. Unfortunately there is no error information so I don't know how to debug this. I turned debugging on but I do not know how to interpret the output.

    Net::SMTP>>> Net::SMTP(2.31)
    Net::SMTP>>> Net::Cmd(2.29)
    Net::SMTP>>> Exporter(5.63)
    Net::SMTP>>> IO::Socket::INET(1.31)
    Net::SMTP>>> IO::Socket(1.31)
    Net::SMTP>>> IO::Handle(1.28)
    Net::SMTP=GLOB(0x971d1b8)>>> QUIT
    Net::SMTP=GLOB(0x971d1b8)<<< 221 ...

    The connection seems to work because it does not die on the 'new'.
    Code:
    my $smtp=Net::SMTP->new("mailer.mydomain.com") || die("Cannot open connection: $!\n");
    $smtp->mail('myemail') || die("Cannot set sender: $!\n");
    .
    .
    .
    There does not seem to be much that can do wrong this soon in the code but obviously I've found something. Can someone help me debug this? TIA.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,230
    Rep Power
    593
    I don't know why but suddenly this started working. I did not make any changes I can point to as having anything to do with the problem other than some debug. However, once the debug was removed it continued to work.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    928
    I would recommend using a higher level module such as Mail::Transport::SMTP.

    If you're going to use Net::SMTP, I would recommend reading RFC 5321 first. Net::SMTP is a thin layer over the SMTP protocol and requires an understanding of that protocol to use. (For example, SMTP servers often expect you to authenticate yourself.)

    To get more detailed error information from the Net::SMTP module, print out the value of $smtp->code and $smtp->message on failure. $! is unlikely to contain anything interesting unless there was a socket error.

    It's also odd that you're seeing a QUIT in the debug trace but no MAIL command. Is this part of a larger script? If so, extract out just to code necessary to connect to the SMTP server into a smaller test script. Also can you print out the values of $smtp->banner, $smtp->code and $smtp->message after the call to Net::SMTP->new.

    <edit> -- ah too slow, beaten by an intermittent SMTP server.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,230
    Rep Power
    593
    Thanks for the reply and tips. I found that QUIT odd as well but since the 'mail' command failed I assumed it was some kind of automatic closure. In any case it is now working properly. My guess is that in the course of my debugging I unknowingly added/removed/corrected something subtle that the compiler did not flag.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,230
    Rep Power
    593
    I'm not quite there yet. I still have a couple of issues I need to resolve but I cannot get any message info. When I print $smtp->message I get this:

    Net::SMTP=GLOB(0xa012d10)->message

    I cannot find anything in the documentation on either message or code so I don't know what I am doing wrong. TIA.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,230
    Rep Power
    593
    Never mind. I figured it out.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,873
    Rep Power
    1225
    I agree with OmegaZero, you really should be using a higher level smtp module.

    Please post a short but complete script that demonstrates the problem and include all output that it generates. You can obfuscate any private data, but don't remove it.

    Once we have that, we will be more able to point out the cause and solution to the problem.

IMN logo majestic logo threadwatch logo seochat tools logo