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

O.k.. I've go a list of email address which I pulled out of my user database...

Is there a way to email each user separately from a single SENDMAIL command line???

Example:
&sendemail, *multiple users*, 'SUBJECT', "BODY";

Thanks in advance
__________SysAdm

Replies are listed 'Best First'.
Re: Multipe emails using SENDMAIL?
by maverick (Curate) on Aug 21, 2001 at 08:40 UTC
    You might want to check into Mail::Bulkmail. It has a slew of nice features, is fast, etc. I have code that uses Mail::Bulkmail that I can share if you want to give it a try.

    Executing sendmail directly can be risky and error prone.

    /\/\averick
    perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

Re: Multipe emails using SENDMAIL?
by MZSanford (Curate) on Aug 21, 2001 at 13:24 UTC
    First off, i agree with /\/\averick that calling sendmail directly is risky, but if you must do such things (e.g. prod machine and modules cannot be installed with out internal QA :-( ), sendmail will take multiple addresses (untested code ahead):
    my $local_addr = 'some@addr.com'; my @addrs = qw(mzsanford@cpan.org foo@perl.com joe@cool.com); my $mail_string = join(',',@addrs); open(MAIL,"| /usr/lib/sendmail -t") || die "fork() : $!\n"; print MAIL "From: $local_addr\n"; print MAIL "To: $local_addr\n"; print MAIL "Bcc: $mail_string\n\n"; print MAIL "Subject: hello\n"; print MAIL "foo, bar, and the like.\n"; print MAIL "\n.\n"; close(MAIL) || die "close() : $!\n";
    ... but i am not sure, and my unix box is down at the moment so i can't test. Also, they will get a mail from you, to you, and BCC'd to them ... common spammer stuff ... i even have a filter for it.
    can't sleep clawns will eat me
    -- MZSanford
Re: Multipe emails using SENDMAIL?
by EvanK (Chaplain) on Aug 21, 2001 at 11:40 UTC
    well, you could email all of them seperately, but if i understand correctly, you're wanting to avoid exactly that? so you could fork() child processes for each email address and send the seperate emails all at the same time...

    ______________________________________________
    RIP
    Douglas Noel Adams
    1952 - 2001

      There's no reason to fork in this situation when this is something that can be done easily using the SMTP protocol. Forking introduces a WHOLE mess of unnecessary problems into a simple script that could potentially kill the server ie, infinite loops. Also, forking without knowing how to clean up your children is a bad idea. AND in the event the forking loop spins off into infinity and a successful connection is made to a mail server, think of the load that'll put on the mail server unnecessarily (it could potentially use up all available file descriptors and render the mail server unreachable until the connections close).

      bottom line, that is WAY too complicated, but if you're still interested I wrote up a node on forking that might be useful. I took time to read several different books and various web pages online for possible problems that I could encounter.

      K.I.S.S.


      -brad..
        But if i understood SysAdm's original message, he didn't plan on using a direct SMTP connection, he was just gonna use sendmail...

        ______________________________________________
        RIP
        Douglas Noel Adams
        1952 - 2001

Re: Multipe emails using SENDMAIL?
by mischief (Hermit) on Aug 21, 2001 at 18:24 UTC

    From the sendmail man page:

    NAME sendmail - an electronic mail transport agent SYNOPSIS sendmail [flags] [address ...]

    So, you just add extra addresses at the end of the command line when calling sendmail.

    Although this has nothing to do with Perl, really.

Re: Multipe emails using SENDMAIL?
by reyjrar (Hermit) on Aug 21, 2001 at 21:02 UTC
    You could also communicate with the MTA on the protocol level, which would be independant of where sendmail is, whether or not you're using qmail or whatever smtp agent.
    cleen wrote a good node on this a while back. I currently use that in all the scripts and programs I write to send email to a list of users. Its portable accross many different UN*X's and doesn't rely on that local machine running an MTA as I can specify the mail host to connect to.

    You might also be interested in the Net::SMTP, Net::POP3 which do effectively the same thing in a module.


    -brad..
    'reinvent the wheel and make it bigger, better, and with metal spikes, yeah, we can never have enough metal spikes'