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

Please help me: the following code works (and send me the e-mail):
$mailprog = '/usr/sbin/sendmail'; open (MAIL, "| $mailprog -t -oi")||die "server error; Please try again + later"; print MAIL "To: falcons\@polbox.com\n"; print MAIL "Subject: do-kina\n\n"; foreach $key (keys(%formdata)) { print MAIL "$key = $formdata{$key}\n"; } close MAIL;
and this doesn't work (and nothing is sent):
$mailprog = '/usr/sbin/sendmail'; open (MAIL, "| $mailprog -t -oi")||die "server error; Please try again + later"; print MAIL "To: m.kwest\@cematsil.com.pl\n"; print MAIL "Subject: do-kina\n\n"; foreach $key (keys(%formdata)) { print MAIL "$key = $formdata{$key}\n"; } close MAIL;
the only small change is in the e-mail address. Could you tell me what's wrong please? Regards, sOKOle

Replies are listed 'Best First'.
Re: sendmail trouble
by Abigail-II (Bishop) on Sep 05, 2003 at 13:59 UTC
    and this doesn't work

    What do you mean by "doesn't work"? Does the program die horribly? Do the letters fall of your screen? Does sendmail get anything? Does sendmail refuse anything? Does sendmail crash? Does sendmail queue for later delivery? Does the ceiling come down?

    Be more explicit!

    Abigail

      in the first case the e-mail reach the address

      in the second case no e-mail reach the address

      both addresses are correct for sure,
      sOKOle
        And what does your mail log file say? Has sendmail accepted the mail? Has sendmail attempted to deliver the mail? If so, what reason did it give for not succeeding?

        Abigail

Re: sendmail trouble
by blue_cowdawg (Monsignor) on Sep 05, 2003 at 14:31 UTC

        the only small change is in the e-mail address.
    Check out Email::Valid and use it to validate the destination email addresses before trying to send the email.

    Also in my not so humble opinion using a module like MIME::Lite or Mail::Send can save you a lot of grief.


    Peter L. Berghold -- Unix Professional
    Peter at Berghold dot Net
       Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.
      Hi there blue_cowdawg,
      Not meaning to tread on your toes but your answer could be a little misleading regarding Email::Valid, E::V cannot validate that the actual address is correct, only that there is an MX record for the domain (which is what I think you meant*) and that the address itself is RFC822 compliant.

      /me scuttles away quickly from flying detritus

      * This uses Net::DNS and is hellishly slow if the MX cannot be verified.

            Not meaning to tread on your toes
        Don't worry... I wear steel toed sandals here at The Monastary! ;-)

            E::V cannot validate that the actual address is correct, only that there is an MX record for the domain
        Agreed, and in my at the time caffeine deprived state I read between the lines and came to the conclusion that the trouble the OP was running into was Sendmail barfing on the email address. The only things I can think of that would cause that would be
        1. The address is malformed (not the case IIRC)
        2. The domain doesn't exist or lacks an MX
        3. It is an address from the local domain that is wrong
        4. Stuff I can't think of right now...
        In the first two cases Email::Valid is a legitimate tool. I do, however, stand by my answer of using Mail::Send or MIME::Lite instead of piping into sendmail.

            This uses Net::DNS and is hellishly slow if the MX cannot be verified.
        Actually this is a case where YMMV depending on a number of factors. I've used the module extensively under all sorts of conditions and for the exceptions of some boundary conditions it has worked well for me. A misconfigured DNS client or server can cause you problems but those issues are out of scope here.


        Peter L. Berghold -- Unix Professional
        Peter at Berghold dot Net
           Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.
Re: sendmail trouble
by jdtoronto (Prior) on Sep 05, 2003 at 17:27 UTC
    Your response to others questions indicates that the email reaches one address but not the other.

    In fact that probably means that the problem has nothing to do with your script. The answer quite likely has more to do with the configuration of the mail servers you are sending to. If the machine you are sneding from does not have Reverse-DNS set-up or does not have an MX record pointing to the server that sent the mail then it may be rejected by servers which it attempts to contact.

    If your machine is on a dial-up, cable or DSL service then it is also likely to be rejected. Almost certainly if the IP address of the machine is dynamically allocated.

    Nobody is 'required' to accept email from anybody, in this era of rampant spam and attacks using email many sys-admins lock down machines so that email is only accepted from machines that have reverse DNS records, statically assigned addresses and possibly that are also findable as a valid MX for the domain in question.

    As somebody else suggested - read the mail server logs!

    jdtoronto