in reply to Sending e-mail problem

The classic answer would be "Use Net::SMTP" or a similar module instead of cooking up your own.

In this case I hesitate to recommend that module though since last time I checked it was still in need of some improvements to really make it useful (mostly in returning useful error codes to the caller)

As for your code, there's plenty of things you should change:

There's probably a few more things but those would be a good start.

Replies are listed 'Best First'.
Re^2: Sending e-mail problem
by muntfish (Chaplain) on Jun 24, 2004 at 15:34 UTC

    Can you clarify what you mean by Net::SMTP not returning useful error codes to the caller?

    I use Net::SMTP in various applications, and haven't noticed this deficiency. Since Net::SMTP is a subclass of Net::Cmd you can get the 3-digit return code very easily, as the following snippet shows:

    $smtp = Net::SMTP->new($host); print ">>Connected to $host\n"; print $smtp->banner()."\n[".$smtp->code()."] ".$smtp->message()."\n"; $smtp->mail($fromaddr); print ">>MAIL FROM: $fromaddr<<\n[".$smtp->code()."] ".$smtp->message( +)."\n"; $smtp->to($toaddr); print ">>RCPT TO: $toaddr<<\n[".$smtp->code()."] ".$smtp->message()."\ +n"; $smtp->data(); print ">>DATA\n[".$smtp->code()."] ".$smtp->message()."\n"; $smtp->datasend("From: \"$fromname\" <$fromaddr>\n"); $smtp->datasend("To: $toaddr\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); $smtp->datasend("$data\n"); $smtp->dataend(); print ">>End of DATA\n[".$smtp->code()."] ".$smtp->message()."\n"; $smtp->quit; print ">>Closed connection\n[".$smtp->code()."] ".$smtp->message()."\n +";

    Maybe I misunderstood you - if so, apologies.

    But returning to the original problem, if it was once working and now is not, there could be something up with your mail server. Maybe someone has changed the config, so that it expects you to authenticate yourself first, or something. At the very least, you should amend your existing code to print out the responses from the server, and see what that tells you.

    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&;

      I stand corrected. I completely missed the reference in the Net::SMTP doc to Net::Cmd, and thus the code() and message methods.

      So my objection so Net::SMTP is invalid indeed. Thanks for enlightening me.

Re^2: Sending e-mail problem
by iburrell (Chaplain) on Jun 24, 2004 at 21:46 UTC
    Also, not putting the brackets around the email address in the MAIL and RCPT commands. Mail servers are very accepting but it is best to follow the standards especially when it is trivial to do so. They should be:
    MAIL FROM:<from@example.com> RCPT TO:<to@example.com>