On Sat, Jul 05, 2003 at 12:25:47PM +0000, Pablo Fischer wrote:

> >   use Mail::Sendmail;
> Load Module. Can I save it in my working dir? /home/unmada/MailP/?

Sure.  You need to make sure that it will appear on @INC (the module
include path that Perl uses to find your modules).  Probably the
easiest way to do that is to set the PERL5LIB environment variable to
whatever directory you save it in.  Notice that the Mail::Sendmail
module name means that Perl is looking for a FILE named 'Sendmail.pm'
in a DIRECTORY named 'Mail'.

I would suggest doing the following:

    cd ~
    mkdir -p perl5mod/Mail
    save Sendmail.pm to ~/perl5mod/Mail
    export PERL5LIB=/home/unmada/perl5mod

You probably want to put that last line in your .profile so it gets
reset every time you log in.


> >   $i = 100;
> number of mails..

Correct; the assumption is that each mail will contain 10 mail adds.

> >   while ($i--) {
> >     $body_of_message = ...;
> iteration..

Yes.  Note that the '...' means "whatever you need to do to compose
the body of your message, do it here.


> >     sendmail(%mail) or die $Mail::Sendmail::error;
> send mail and print errors

Yep.  Thinking about it, you might want to change the 'die' to a
'warn'--that way, if one block fails, you can continue.  On the other
hand, if sendmail() fails, the most likely reason is because it can't
connect to your mail server, or somesuch.

Oh, one thing I forgot.  You should specify your mail server in the
constructor, as follows:

> >     %mail = ( To      => '[EMAIL PROTECTED]',
> >               From    => '[EMAIL PROTECTED]',
> >               smtp    => 'mail.mycompany.com',  # NOTE THIS LINE
> >               Subject => 'mailadds, group ' . (100 - $i + 1),
> >               Message => $body_of_message,
> >         );




> Thanks! I was thinking in this option, but also Im looking for a second 
> option, to know if In sendmail I could manage the threads (to send each mail, 
> each 5 seconds).. I know this is a perl list, but.. does someone knows if I 
> can?
> thanks!
> 
> Pablo

Well, do you really want to do that?  The whole point is to avoid
sending the messages too quickly.  If you parallelize it, then the
messages go out faster, and you may end up looking like a spammer.

If you DO want to do it, here's how: 

First, you need Perl 5.8 with the threading option selected at compile
time.  To see if you do, type 'perl -v'.  If the first line looks
something like this:

    This is perl, v5.8.0 built for i586-linux-thread-multi

Then you have threading capability.

The docs on threads are here:

    http://www.perldoc.com/perl5.8.0/pod/perlthrtut.html

and also come with Perl:

    perldoc perlthrtut

To do this threaded, your script would look (something) like this (I
haven't tested it):


#!/usr/bin/perl 

use warnings;
use threads;
use Mail::Sendmail;


for(1..10) { 
    threads->new(\&mail, $_)->detach() ;
} 

sub mail {
    my $num = shift;
    my $start = $num * 100;       # 0, 100, 200, etc.
    my $end   = $num * 100 + 99;  # 99, 199, 299, etc

    #  Build the body of the mail here.  $start and $end are the 
    #  indexes of the mailadds that should be in the mail
    my $body = ???;

    %mail = ( To      => '[EMAIL PROTECTED]',
              From    => '[EMAIL PROTECTED]',
              smtp    => 'mail.server.com';
              Subject => 'some subjet',
              Message => $body,
           );

    sendmail(%mail) or die $Mail::Sendmail::error;
    print "OK. Log says:\n", $Mail::Sendmail::log;
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to