in reply to Sending two messages thru an smtp server with authentication

I'm not sure why it's happening but it just makes more sense to me to try and send two messages while only authenticating once.

Untested code follows:

#!/usr/bin/perl use Net::SMTP; use strict; use warnings; my $smtp = Net::SMTP->new('smtpauth.earthlink.net', Hello => 'milkbone.org', Debug => 1) or die +"death"; $smtp->auth('batkins86@earthlink.net', '***************************'); $smtp->mail('monitor@milkbone.org'); for(1..2) { $smtp->to('test@batkins.com'); $smtp->data(); $smtp->datasend("To: postmaster\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); $smtp->dataend(); } $smtp->quit;

Replies are listed 'Best First'.
Re: Re: Sending two messages thru an smtp server with authentication
by batkins (Chaplain) on Jul 11, 2003 at 16:37 UTC
    The problem is that the messages aren't sent out constantly in the real app. It could be five hours between each send, so the SMTP server would boot me by then.
    milkbone - perl/tk instant messaging - it's the only way to fly

    You know anyone who'll debug two million lines of code for what I get this job?
    - Dennis Nedry

      So what happens if you put a sleep statement at the end of the loop? Something like:
      #!/usr/bin/perl use Net::SMTP; use strict; use warnings; for(1..2) { my $smtp = Net::SMTP->new('smtpauth.earthlink.net', Hello => 'milkbone.org', Debug => 1) or die +"death"; $smtp->auth('batkins86@earthlink.net', '***************************' +); $smtp->mail('monitor@milkbone.org'); $smtp->to('test@batkins.com'); $smtp->data(); $smtp->datasend("To: postmaster\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); $smtp->dataend(); $smtp->quit; sleep(5); }

      Perhaps Net::SMTP hasn't fully cleaned up before you call it again? Don't think it would matter but I'm trying to cover all the bases...