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

I am sending some mail via Net::SMTP. In the PODs regarding the recipient method, it says
The `recipient' method can some additional OPTIONS which is passed in hash like fashion, using key and value pairs. Possible options are: Notify => SkipBad => ignore bad addresses If `SkipBad' is true the `recipient' will not return an error when a bad address is encountered and it will return an array of addresses that did succeed.
My first point of confusion is about the Notify option. What does it do?

However, what I'm really interested in is the SkipBad option.

I would like, as it says, to get back a list of addresses that did succeed.

However, a simple test:

#!/usr/bin/perl use Net::SMTP; my $smtp = Net::SMTP->new('rintintin.colorado.edu'); die "Ugh." unless defined $smtp; my @recipients = $smtp->recipient('collin.starkweather@colorado.edu',' +joe@flugwumpet.com', Notify => 1, SkipBad => 1); print "Recipients are [@recipients]\n";
returns
What? ~/bin/test.pl Recipients are [0] What?
(Note I also tried it without the Notify option.)

The first address I know to be good, the second bad. The PODs are fairly unambiguous. Is this just bad documentation? Has anyone else actually gotten this option to work? Am I totally misreading what seems to be a fairly straightforward statement of how it works?

Any help from someone who has either gotten this to work or positively knows whether it should work or not would be much appreciated.

Thanks in advance, brothers :-)

Edit Masem 2001-08-24 - PRE to CODE tags

Replies are listed 'Best First'.
Re: Simple Net::SMTP question
by dga (Hermit) on Aug 24, 2001 at 02:12 UTC

    Having read the documentation and the relevant code I believe this to be a documentation defect.

    You must not only pass a hash-like string but it must be in fact an actual hash.

    Try changing your options to

    my @recipients = $smtp->recipient('collin.starkweather@colorado.edu',' +joe@flugwumpet.com', { Notify => 1, SkipBad => 1 });

    I think it will magically begin to work.

      Thanks a million! That's exactly it.

      On a final note, now that I have it working, I'm getting

      Net::SMTP::recipient: DSN option not supported by host at /home/bogususer/bin/test.pl line 6
      
      from several of my campus mail relays. (See this for more information about DSN.) In lieu of DSN, all of the e-mail addresses are returned whether they are valid or not.

      So the moral of the story is that SkipBad relies on DSN, and not all SMTP servers support DSN.

      Thanks again for your help!

        Not quite. Probably Notify is the one that requires DSN to work on the server (normally doesn't).

        To check wether a recipient is valid or not, the module depends on the response from the mail server. Relaying servers are often configured to delay address checks and to accept things that seem vaguely as email addresses.

        This is probably what you're seing.

        Good luck.

Re: Simple Net::SMTP question
by shotgunefx (Parson) on Aug 24, 2001 at 00:10 UTC
    Does your code work when all address are good?

    -Lee

    "To be civilized is to deny one's nature."
      Thanks for your prompt reply :-)

      I discovered I forgot the $smtp->mail() call in the above example, but it doesn't change the fact that I can't get the SkipBad option to work.

      I tried all of the following combinations, uncommenting the recipient lines one at a time:

      #!/usr/bin/perl
      use Net::SMTP;
      my $smtp = Net::SMTP->new('mail.bogusdomain.com');
      die "Ugh." unless defined $smtp;
      $smtp->mail($ENV{USER});
      my @recipients = $smtp->recipient('totallybogus', SkipBad => 1);
      #my @recipients = $smtp->recipient('totallybogus', Notify => 1, SkipBad => 1);
      #my @recipients = $smtp->recipient('joe@flugwumpet.com', Notify => 1, SkipBad => 1);
      #my @recipients = $smtp->recipient('joe@flugwumpet.com', SkipBad => 1);
      #my @recipients = $smtp->recipient('bogususer@bogusdomain.com', Notify => 1, SkipBad => 1);
      #my @recipients = $smtp->recipient('bogususer@bogusdomain.com', SkipBad => 1);
      print "Recipients are '@recipients'\n";
      $smtp->data();
      $smtp->datasend('To:  bogususer@bogusdomain.com, joe@flugwumpet.com' . qq{\n});
      $smtp->datasend('Subject:  A test.' . qq{\n});
      $smtp->datasend("\n");
      $smtp->datasend("This is a test.");
      $smtp->dataend();
      $smtp->quit();
      
      and in every case, I got
      What? ~/bin/test.pl
      Recipients are '1'
      What?
      
      The address bogususer@bogusdomain.com is a valid address (I changed the user and domain names in this post to protect the innocent), joe@flugwumpet.com is an invalid address, and totallybogus is an *obviously* bad address.

      I even received both e-mails to the correct recipient and failure notices to the bogus addresses from the mailer daemon.

      I am seriously considering the possiblity that the SkipBad option simply does not work as advertised. That would seem odd given that Net::SMTP is probably one of the most heavily used modules on the CPAN.

      Harumph!

        dga is right , BUT
        When I pass the options as a hash, I get

        Can't use string ("1") as an ARRAY ref while "strict refs" in use at /usr/local/lib/perl5/site_perl/5.6.1/Net/SMTP.pm line 278.

        The code it is choking on is in the recipient sub.

        if(defined ($v = delete $opt{Notify}) )

        Why is this treating $opt{Notify} as an array reference? It's not. (It's set to 1)

        I'm using version 2.16.
        I am very perplexed at how it's coming up with this context.

        -Lee

        "To be civilized is to deny one's nature."