Hi Leon,

Thanks for the recommendation Philip:-)

You definitely Don't! want to use Net::SMTP for 1 message withmultiple
recipients.
The problem you have with creating one message with multiple recipients is
it is very, very slow, and only one sendmail process will be spawned to send
the mail.

So you have two options.

1) Sort your email addresses by domain, and then use Net::SMTP to create 1
message and give it ,say all the yahoo.com recipients. his means the spawned
sendmail process will only have to connect to one external mail server to
deliver the whole message. Then move on to the next domain.

or

2) use Mail::Bulkmail.
An excellent module which allows you to create a file which contains all the
emailaddresses you wish to use.
Then pass that filehandle to the Bulkmail module and let it worry about
generating the individual messages.
Something like this:-
                open (USERLIST,"$User_File")|| die ("Unable to open
$User_File");           #File containing list of recipient mail addresses,
and mappings
                open (BANNED,"$Banned_File")|| warn ("No Banned File Today
$Banned_File");    #list of domains/adresses not to send to
                open (BAD,">$Bad_File")|| die ("Unable to open $Bad_File");
#empty file which bulkmail will write failed addresses.
                open (ERROR,">$Error_File")|| die ("Unable to open
$Error_File");    #same as above , but will write the entry as it appears in
the USERLIST.

                my $bulk=Mail::ModBulkmail->new(
                        From=>$fromaddress,
                        Subject=>$Subject,
                        Message=>$Message,
                        'X-SportsUserID'=>'ZZ_USERID_ZZ',
                        Map=>{
                                'ZZ_DATE_ZZ'=> $date,

BULK_FILEMAP=>"BULK_EMAIL::ZZ_USERID_ZZ::ZZ_FIRSTNAME_ZZ"
                                },
                        'LIST'=>*USERLIST,
                        'GOOD'=>*GOOD,
                        'BAD'=>*BAD,
                        'BANNED'=>*BANNED,
                        'ERROR'=>*ERROR,
                        );

                $bulk->bulkmail();

                close (USERLIST);
                close (BANNED);
                close (BAD);
                close (GOOD);
                close (ERROR);

                open (GOOD,"<$Good_File")|| die ("Unable to open
$Good_File");
                my $success_list;
                while (my $line=<GOOD>)
                {
                        my ($tmp) = $line =~/(.*)\:\:.*?\:\:.*$/i;
                        $success_list.=$tmp;
                }
                close (GOOD);


Bulkmail takes filehandles as its arguments.

THe USERFILE looks like this:-

[EMAIL PROTECTED]::123456::Martin
[EMAIL PROTECTED]::123457::Leon

Bulkmail allows mapping files, very useful for bulkmail purposes. It lets
you use a template for your mail message and then will fill in anything
which contains one of the map keywords (ZZ_USERID_ZZ or ZZ_FIRSTNAME_ZZ)
with the userid and firstname given in the map file.

You don't have to use this if you don't want.

However one of the things you'll have to do with bulkmailing people is track
your undeliverables. People make lots of typos when writing their email
address on web pages (I guess this is how you got your email addresses). And
people also make up stupid domain names like [EMAIL PROTECTED]
Now these will cause delays in the mailing process. So you want to weed
these out over time.

The way I do this is I create an X-Header for each recipient and assign that
email address's database ID (Which is why I use the mapping functionality).
Then when undeliverables arrive I can scan through the undeliverable and
look for the original message headers and hey presto theres a userid to use
to update my database.
Warning, not all mail undeliverabel reports look the same, and not all
return the message. I haven't fond a way of getting EVERY undeliverable
recipient from all undeliverable reports, but I do get about 80%.

If you wish to use the X-Headers approach you will have to edit the Bulkmail
module as it didn't support this functionality, I'll give you the lines you
need to add and where you need to add them if you get stuck,


Marty

p.s. I usually manage to get through about 40,000 mail addresses in about 12
hours.



----- Original Message -----
From: "Leon" <[EMAIL PROTECTED]>
To: "Perl-Win32-Users Mailing List"
<[EMAIL PROTECTED]>
Sent: Thursday, May 18, 2000 12:00 AM
Subject: Thoughts on writing bulk mail sender...


> (...And no this is not for spam purposes!)
>
> Hi,
>
> I am thinking of re-writing some java code we have here (in Perl of
course)
> which sends emails to our clients based on searches they have saved on our
> database - i.e. we run their search every day and send them an email based
> on the results.
>
> It needs to be able to send around 20,000 emails per day, averaging 10k
> each, some with MIME attachments. I use PL/SQL to create a table full of
> email addresses and the body text to send, so all I need to do on the Perl
> side is access this table, extract the data and send the emails to the
> relevant addresses.
>
> Does anyone have any performance enhancing considerations that I should
> build into my program? I was thinking along the lines of using DBD-Oracle
> to select a certain number of records at a time, and then loop through the
> resultset and send one at a time with Net-SMTP.
>
> Not knowing much about mail servers and how to treat them, is this the
> practical way to go? Can I just pass each message onto the server and let
> it worry about queue management? The server will be sendmail on Solaris 7.
>
> Also, I want the program to be running on a loop so that if it is idle it
> constantly polls the database for new email to send.
>
> Any thoughts would be warmly appreciated,
>
> Cheers,
>
> Leon.
>
> ---
> You are currently subscribed to perl-win32-users as: [EMAIL PROTECTED]
> To unsubscribe, forward this message to
>          [EMAIL PROTECTED]
> For non-automated Mailing List support, send email to
>          [EMAIL PROTECTED]


---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to