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

im writing a script that sends email to a few big wigs detailing the information a user has input into an order form. The code is below:

#!/usr/local/bin/perl -wT use Net::SMTP; print "Content-type: text/plain", "\n\n"; my $DEBUG = 1; if ($DEBUG) { $| = 1; open(STDERR, ">&STDOUT"); } # smtp server name my $serverName = "mail.blah.com"; # create a new smtp object $smtp = Net::SMTP->new($serverName, Debug => 1); # if you can't connect then dont proceed with the rest of the script die "Couldn't connect to server" unless $smtp; # initiate the mail transaction # your "real" email address my $from = "crap\@blah.com"; # recipient's "real" email address my $to = "poop\@toilet.com"; $smtp->mail($from); $smtp->to($to); # start the mail $smtp->data(); # send the header # this address will appear in the message $smtp->datasend("To: poop\@toilet.com\n"); # so will this one $smtp->datasend("From: crap\@blah.com\n"); $smtp->datasend("Subject: Online Ordering Test Message\n"); $smtp->datasend("\n"); # send the body $smtp->datasend("TESTING TESTING TESTING\n\n"); # send the termination string $smtp->dataend(); # close the connection $smtp->quit();

i get this in the browser window:

Relaying denied. IP name possibly forged

i really dont know whats going on. if i send an email using this script to myself i dont get that error, but i also dont get the mail.

i also get these errors:

Net::SMTP=GLOB(0x8114994)<<< 500 5.5.1 Command unrecognized: "To: poop +@toilet.com" Net::SMTP=GLOB(0x8114994)>>> QUIT Net::SMTP=GLOB(0x8114994)<<< 500 5.5.1 Command unrecognized: "From: cr +ap@blah.com"

any help is greatly appreciated

Janitored by Arunbear - added readmore tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: SMTP problem
by mattriff (Chaplain) on Nov 01, 2004 at 16:59 UTC
    Try checking the return values of the calls to mail() and to() -- it is most likely rejecting the data being sent at one of those points (at least for the last set of errors). Because of that, your request to send data is similarly denied, so when you are sending the headers, it is still trying to read them as SMTP commands, which they of course are not.

    This is probably not a Perl issue at all -- just an issue of what the SMTP server will accept. You can telnet to port 25 of the mail server manually and see for yourself, sending from your end:

    HELO your.server.name MAIL FROM: your@email.addr RCPT TO: their@email.addr DATA Subject: your e-mail here testing .
    After the helo,mail and rcpt commands, you should get a return code of 250 (ok), or one that starts with 4 (temporary denial), or 5 (permanent denial) and some text description of the action.

    The helo is usually a gimme, but that first error message you get in the browser might suggest it's comparing the answer you give here to the reverse lookup of the IP you are connecting from and denying because they don't match.

    After the DATA command, you should get a 354 return code if it's going to accept your mail.

    After terminating the mail with a line that's just a dot and return, you'll again get a 250 for ok or a temporary or permanent failure message.

    This is a bit of a simplification of things -- for more than you really want to know, see RFC 821.

Re: SMTP problem
by demerphq (Chancellor) on Nov 01, 2004 at 17:50 UTC

    Your SMTP server wont relay material from crap@blah.com. Most likely this is because blah.com isn't the domain the server normally handles. At least thats been the reason when ive seen this error. For instance if I send from "demerphq@lala.com" i get the error you see. If i send from "demerphq@mycompany.com" I dont.

    BTW, the part of the code that determines who you are sending from/to is the $smtp->from() and $smtp->to() commands, NOT the text you sending in "To: ..." the latter stuff is strictly for humans and their mail cleints and is ignored when the mail is sent. Thats why its possible to send or receive mails without these headers at all.

    ---
    demerphq

      I would second that opinion, especially if you see this sort of message: "Relaying denied. IP name possibly forged." It sounds like you are being blocked by the mail server. You might want to have a chat with the mail administrators to see if this is the case.
Re: SMTP problem
by TedPride (Priest) on Nov 01, 2004 at 20:48 UTC
    The best solution is to run your own mail server. A few of your emails will probably still be rejected by the recipient ISP's ("We don't accept emails from dynamic IPs), but most of them will get through. I know this because I wrote a mass email script for sending bulletins to homeschool groups listed on my parents' web site.

    Just be sure to NOT send the same email twice, especially not to the same address. This will get you on the spam lists real fast.

Re: SMTP problem
by cosmicperl (Chaplain) on Nov 01, 2004 at 21:15 UTC
    I always use the Sendmail.pm module to email by SMTP. I think it's now called Mail::Sendmail. It doesn't need to be made in to perl with ppm so you can just include it in your program directory.