|
NAMEMail::Bulkmail - Platform independent mailing list moduleAUTHORJim Thomason, jim@jimandkoka.com (http://www.jimandkoka.com)SYNOPSISuse Mail::Bulkmail /path/to/conf.file my $bulk = Mail::Bulkmail->new( "LIST" => "~/my.list.txt", "From" => '"Jim Thomason"<jim@jimandkoka.com>', "Subject" => "This is a test message", "Message" => "Here is my test message" ) || die Mail::Bulkmail->error(); $bulk->bulkmail() || die $bulk->error; Don't forget to set up your conf file! DESCRIPTIONMail::Bulkmail gives a fairly complete set of tools for managing mass-mailing lists. I initially wrote it because the tools I was using at the time were just too damn slow for mailing out to thousands of recipients. I keep working on it because it's reasonably popular and I enjoy it.In a nutshell, it allows you to rapidly transmit a message to a mailing list by zipping out the information to them via an SMTP relay (your own, of course). Subclasses provide the ability to use mail merges, dynamic messages, and anything else you can think of. Mail::Bulkmail 3.00 is a major major major upgrade to the previous version (2.05), which was a major upgrade to the previous version (1.11). My software philosophy is that most code should be scrapped and re-written every 6-8 months or so. 2.05 was released in October of 2000, and I'm writing these docs for 3.00 in January of 2003. So I'm at least 3 major re-writes behind. (philosophy is referenced in the FAQ, below) But that's okay, because we're getting it done now. 3.00 is about as backwards compatible to 2.00 as 2.00 is to 1.00. That is to say, sorta. I've tried to make a note of things where they changed, but I'm sure I missed things. Some things can no longer be done, lots are done differently, some are the same. You will need to change your code to update from 1.x or 2.x to 3.00, though. That's a given. So what's new for 3.00? Lots of stuff. Immediate changes are: * code compartmentalization * multi-server support * conf file The immediate change is that the code is now compartmentalized. Mail::Bulkmail now just handles ordinary, non-dynamic mailings. See Mail::Bulkmail::Dynamic for the merging and dynamic text abilities from the prior versions. Server connections are no longer handled directly in Mail::Bulkmail (Smtp attribute, Port attribute, etc.), there is now a separate Mail::Bulkmail::Server object to handle all of that. And everything subclasses off of Mail::Bulkmail::Object, where I have my super-methods to define my objects, some helper stuff, and so on. It's just a lot easier for me to maintain, think about it, etc. if it's all separated. It's also easier for you, the user, if you want to make changes to things. Just subclass it, tweak it, and use it. Very straightforward to modify and extend now. 2.x and below *could* do it, but it wasn't really that easy (unless you were making very trivial changes). This should rectify that. Another major change is the addition of multi-server support. See the docs in Mail::Bulkmail::Server for more information. You can still specify one SMTP relay if that's all you've got, but if you have multiple servers, Mail::Bulkmail can now load balance between them to help take the stress off. No matter what, the biggest bottleneck to all of this is network performance (both to the SMTP relay and then from the relay to the rest of the world), so i wanted to try and help alleviate that by using multiple servers. I know that some people were doing that on there own with small changes, but this allows you to do it all invisibly. And finally, finally, finally there is a conf file. Documentation on the format is in Mail::Bulkmail::Object. It's pretty easy to use. This is the conf file format that I designed for my own use (along with most of the rest of Mail::Bulkmail::Object). The software also has the ability to read multiple conf files, if so desired. So no more worrying about asking your sysadmin to tweak the values in your module somewhere up in /usr/lib/whatever Just have him create the conf file you want, or pass in your own as desired. conf_files are specified and further documented in Mail::Bulkmail::Object, in an internal array called @conf_files, right at the top of the module. To specify a universal conf file, put it in that array (or have your sysadmin do so). Alternatively, you can also add a conf_file via the conf_files accessor. Mail::Bulkmail->conf_files('/path/to/conf_file', '/path/to/other/conf_file'); #, etc. But the recommended way is to specify your conf file upon module import. use Mail::Bulkmail 3.00 "/path/to/conf/file"; In addition, there is the usual plethora of bug fixes, tweaks, clean-ups, and so on. And yes, the horrid long-standing bug in the Tz method is fixed! No, honest. I'm also trying a new documentation technique. The pod for a given method is now in the module by that method, as opposed to everything being bunched up at the bottom. Personally, I prefer everything being bunched up there for clarities sake. But from a maintenance point of view, spreading it all out makes my life much easier. requiresPerl 5.6.0, Socket (It probaly can get by with less than 5.6.0, but I haven't tested it in such an environment) ATTRIBUTESFrom
Stores the From address of this mailing. Must be a valid email address, unless Trusting is set. Really really should be a valid email address anyway. From is no longer used as the Sender, as was the behavior in prior versions. Now, Mail::Bulkmail first tries to use the Sender as the Sender, and failing that, falls back on the from. $bulk->From('"Jim Thomason"<jim@jimandkoka.com>'); print $bulk->From; To Stores the To address of this mailing. Must be a valid email address, unless Trusting is set. Really should be a valid email address anyway. To is used if you have use_envelope set to 1. See use_envelope, below. If you are not using the envelope, then the actual email address that we are currently on is used instead and ->To is never used at all. $bulk->To('jimslist:;'); print $bulk->To; As of 3.00, ->To may contain either a valid email address or a valid group definition. A group definition is as follows (pseudo-regex): Groupname:(address(,address)*)?; i.e., "the group name", then a colon, then an optional list of email addresses, then a semi-colon $bulk->To('jim@jimandkoka.com'); $bulk->To('MyList:jim@jimandkoka.com'); $bulk->To('MyList:;'); Are all valid addresses. Only the ->To attribute may accept group syntax emails Sender Stores the Sender address of this mailing. Must be a valid email address, unless Trusting is set. Really really should be a valid email address anyway. Sender is mainly used when speaking SMTP to the server, specifically in the RCPT TO command. The spec defines "Sender" as "he who send the message" (paraphrasing), which may not actually be who the message is from. 2.00 used the From address as the Sender. You should specify this, but if you don't then the From value is assumed to be the sender. $bulk->Sender('jim@jimandkoka.com'); print $bulk->Sender; If this value is not set, then Mail::Bulkmail will place a Sender header equal to the From value. Note that the ultimate receiving SMTP server is expected to place a Return-Path header in the message. This Return-Path value will be set to the value of the sender of the message, either ->Sender or ->From. This, in turn, will be the address that bounce backs go to. You should not set a Return-Path header yourself, because bad things will result. ReplyTo Stores the Reply-To address of this mailing. Must be a valid email address, unless Trusting is set. Really really should be a valid email address anyway. Reply-To is used as the address that the user's email client should reply to, if present. If this value is not set, then Mail::Bulkmail will place a Reply-To header equal to the From value. Note that even though the attribute is "ReplyTo", the header set is "Reply-To" $bulk->ReplyTo('jim@jimandkoka.com'); print $bulk->ReplyTo; Subject Boring old accessor that stores the subject of the message. It's really recommended that this is set either at your object or in the conf file, otherwise you'll send out a mailing list with no subject which will probably be ignored. $bulk->Subject("This is the list you signed up for"); print $bulk->Subject; HTML Boolean flag. 1/0 only. A lot of people, though obviously not you, because you're reading the pod, just couldn't figure out how to send HTML messages. It's easy. $bulk->header("Content-type", "text/html"); But it was just too hard for most people. So I added this flag. Here's the order: Check and see if ->header("Content-type") is set, if so then send it. Otherwise, check and see if ->HTML is true, if so, then send a content-type of text/html i.e., an HTML message Otherwise, send a content-type of text/plain i.e., a plaintext message $bulk->HTML(1); print $bulk->HTML(); use_envelope Boolean flag. 1/0 only. use_envelope was the coolest thing I added to Bulkmail 2.00, and is arguably still the best thing I've got here in terms of raw power in your lists. Basically, it's like lasing a stick of dynamite. Mail::Bulkmail is fast. Mail::Bulkmail with use_envelope is mind-numbingly fast. For the uninformed, an email message contains two parts, the message itself and the envelope. Mail servers only care about the envelope (for the most part), since that's where they find out who the message is to and from, and they don't really need to know anything else. A nifty feature of the envelope is that you can submit multiple addresses within the envelope, and then your mail server will automagically send along the message to everyone contained within the envelope. You end up sending a hell of a lot less data across your connection, your SMTP server has less work to do, and everything ends up working out wonderfully. There are two catches. First of all, with envelope sending turned off, the recipient will have their own email address in the "To" field (To: jim@jimandkoka.com, fer instance). With the envelope on, the recipient will only receive a generic email address ("To: list@myserver.com", fer instance) Most people don't care since that's how most email lists work, but you should be aware of it. Secondly, you MUST and I mean MUST sort your list by domain. Envelopes can only be bundled up by domain, so that we send all email to a domain in one burst, all of the email to another domain in the next burst, and so on. So you need to have all of your domains clustered together in your list. If you don't, your list will still go out, but it will be a lot slower, since Mail::Bulkmail has a fair amount more processing to do when you send with then envelope. This is normally more than offset by the gains received from sending fewer messages. But with an unsorted list, you never see the big gains and you see a major slow down. Sort your lists. $bulk->use_envelope(0); print $bulk->use_envelope; force80 Boolean flag 1/0 RFC 2822 recommends that all messages have no more than 80 characters in a line (78 + CRLF), but doesn't require it. if force80 is 1, then it will force a message to have only 80 characters per line. It will try to insert carriage returns between word boundaries, but if it can't, then it will cut words in half to force the limit. Regardless of force80, be warned that RFC 2822 mandates that messages must have no more than 1000 characters per line (998 + CRLF), and that wrapping will be done no matter what. Again, it will try to wrap at word boundaries, but if it can't, it will cut words in half to force the limit. It is recommended that you just have your message with at most 78 characters + CRLF for happiness' sake, and definitely at most 998 characters + CRLF. You may end up with extra CRLFs in your message that you weren't expecting. If your message is not guaranteed to have only < 78 characters + CRLF per line, then it's recommended to have force80 on for full compatibility. Note that force80 will be overridden by ->Trusting('wrapping'); servers arrayref of servers. Okay, this is the first major change between 2.x and 3.x. 2.x had methods to connect to one server (->Smtp, ->Port, etc.). 3.x doesn't have those, and the relevent things are now in Mail::Bulkmail::Server, instead it has a list of servers. servers should contain an arrayref of server objects. You can either create them externally yourself and pass them in in an arrayref, $bulk->servers([\$server, \$server2, \$server3]); or you can create them in your conf file. See the Mail::Bulkmail::Object for more info on the format of the conf file, and Mail::Bulkmail::Server for the attributes to specify. servers will automatically be populated with a list of all servers in the server_list in the conf file if you don't specify anything, so you really don't need to worry about it. If you'd rather use a different server_file, then pass the server_file flag to the constructor: $bulk = Mail::Bulkmail->new( 'server_file' => '/path/to/server_file' ); That will override and ignore the server_file in any conf file, so use it with caution. Realistically, though, just let the program populate in the values of the servers you specified in the conf file and don't worry about this. Be warned that servers will be populated by the constructor if you do not populate servers at object creation. You may still change servers later (before you begin mailing), but there is the slight performance hit to initialize all of the server objects and then throw them away. This doesn't affect mailing speed in anyway, it'll just take a little longer to get started than it should. Message This stores the message that you will send out to the recipients of your list. $bulk->Message('Hi there. You're on my mailing list'); print $bulk->Message; Don't put any headers in your Message, since they won't be transmitted as headers. Instead they will show up in the body of your message text. Use the ->header method instead for additional headers This mutator is known to be able to return: MB020 - could not open file for message MB021 - could not close file for message MB022 - invalid headers from message message_from_file boolean flag. 1/0 only. message_from_file allows you to load your message in from a file. If message_from_file is set to 1, then the value passed to ->Message() will be assumed to be a path to a file on disk. That file will be openned in read mode (if possible), read in, and stored as your message. Note that your entire message text will be read into memory - no matter how large the message may be. This is simply a shortcut so that you don't have to open and read in the message yourself. NOTE This is a bit picky, to put it mildly. No doubt you've read that the constructor actually is taking in its arguments in an array, not a hash. So they're parsed in order, which means you need pass in message_from_file before Message. i.e., this will work: $bulk = Mail::Bulkmail->new( 'message_from_file' => 1, 'Message' => '/path/to/message.txt', ); But this will not: $bulk = Mail::Bulkmail->new( 'Message' => '/path/to/message.txt', 'message_from_file' => 1, ); Ditto for using the mutators. Turn on the flag, i<then> specify the Message. headers_from_message boolean flag. 1/0 only. headers_from_message allows you to specify mail headers inside your message body. You may still specify additional headers in the traditional manner. Note that if you change the value of ->Message (not recommended, but there are times you may want to do so), then any headers that were previously set via headers_from_message will be wiped out. any headers specified in the message will be set when you call ->Message. LIST LIST stores the list of addresses you're going to mail out to. LIST may be either a coderef, globref, arrayref, or string literal. If a string literal, then Mail::Bulkmail will attempt to open that file as your list: $bulk->LIST("/path/to/my/list"); If a globref, it is assumed to be an open filehandle: open (L, "/path/to/my/list"); $bulk->LIST(\*L); if a coderef, it is assumed to be a function to return your list, or undef when it is done: sub L {return $listquery->execute()}; #or whatever your code is $bulk->LIST(\&L); The coderef will receive the bulkmail object itself as an argument. if an arrayref, it is assumed to be an array containing your list: my $list = [qw(jim@jimandkoka.com thomasoniii@yahoo.com)]; $bulk->LIST($list); Use whichever item is most convenient, and Mail::Bulkmail will take it from there. BAD This is an optional log file to keep track of the bad addresses you have, i.e. banned, invalid, or duplicates. BAD may be either a coderef, globref, arrayref, or string literal. If a string literal, then Mail::Bulkmail will attempt to open that file (in append mode) as your log: $bulk->BAD("/path/to/my/bad.addresses"); If a globref, it is assumed to be an open filehandle in append mode: open (B, ">>/path/to/my/bad.addresses"); $bulk->BAD(\*L); if a coderef, it is assumed to be a function to call with the address as an argument: sub B { print "BAD ADDRESS : ", $_[1], "\n"}; #or whatever your code is $bulk->BAD(\&B); The coderef will receive two arguments. The first is the bulkmail object itself, and the second is the data in the form that it was returned from the LIST attribute. if an arrayref, then bad addresses will be pushed on to the end of it $bulk->BAD(\@bad); Use whichever item is most convenient, and Mail::Bulkmail will take it from there. GOOD This is an optional log file to keep track of the good addresses you have, i.e. the ones that Mail::Bulkmail could successfully transmit to the server. Note that there is no guarantee that an email address in the GOOD file actually received your mailing - it could have failed at a later point when out of Mail::Bulkmail's control. GOOD may be either a coderef, globref, arrayref, or string literal. If a string literal, then Mail::Bulkmail will attempt to open that file (in append mode) as your log: $bulk->GOOD("/path/to/my/good.addresses"); If a globref, it is assumed to be an open filehandle in append mode: open (B, ">>/path/to/my/good.addresses"); $bulk->GOOD(\*B); if a coderef, it is assumed to be a function to call with the address as an argument: sub G { print "GOOD ADDRESS : ", $_[1], "\n"}; #or whatever your code is $bulk->GOOD(\&G); The coderef will receive two arguments. The first is the bulkmail object itself, and the second is the data in the form that it was returned from the LIST attribute. if an arrayref, then bad addresses will be pushed on to the end of it $bulk->GOOD(\@good); Use whichever item is most convenient, and Mail::Bulkmail will take it from there. Please note that ->GOOD only says that the address was initially accepted for delivery. It could later fail while transmitting the email address, or it could be an valid but non-existent address that bounces later. It is up to the end user to inspect your error logs to make sure no errors occurred, and look for (and weed out) bounces or other failures later. server_class server_class is a class method that MUST be specified in the conf file. You can initialize it in your program if you really want, but it is strongly recommended to be in the conf file so you don't forget it. server_class is used by the constructor to create the server list to populate into ->servers, ->servers is not populated in the constructor. By default, this should probably be Mail::Bulkmail::Server, to allow mailing. Another useful value is Mail::Bulkmail::Dummy See Mail::Bulkmail::Server and Mail::Bulkmail::Dummy for more information on how to create those objects. Also, if you write your own server implementation, this would be where you'd hook it into Mail::Bulkmail Trusting Trusting specifies your Trusting level. Mail::Bulkmail 3.00 will do its best to make sure that your email addresses are valid and that your message conforms to RFC 2822. But, there is a slight performance hit to doing that - it does have to check things, do regexes, and so on. It's not very slow, but extrapolated over a huge list, it can be noticeable. So that's where Trusting comes in to play. If you set a Trusting value, then certain tests will be skipped. Use this at your own risk. If you tell Mail::Bulkmail to be Trusting, then it won't verify addresses or to make sure your list is under 1,000 characters per line. So if you're Trusting and you pass in bad data, it's your funeral. If there is any chance of invalid data, then don't be Trusting. If you're *positive* there's nothing wrong, then you may be Trusting. Trusting values are set one as key/value pairs. $bulk->Trusting("email" => 1); $bulk->Trusting("wrapping" => 1); $bulk->Trusting("default" => 1); And read back with just the key: $bulk->Trusting("email"); $bulk->Trusting("wrapping"); $bulk->Trusting("default"); default is used as a fall back. So if you didn't specify a Trusting value for "email", for example, it will use the "default" value. Note that the default is only used if a value is not specified. $bulk->Trusting("default" => 1); print $bulk->Trusting("email"); #prints 1 print $bulk->Trusting("default"); #prints 1 $bulk->Trusting("default" => 0); print $bulk->Trusting("email"); #prints 0 print $bulk->Trusting("default"); #prints 0 $bulk->Trusting("email" => 1); print $bulk->Trusting("email"); #prints 1 print $bulk->Trusting("default"); #prints 0 $bulk->Trusting("email" => 0); $bulk->Trusting("default" => 0); print $bulk->Trusting("email"); #prints 0 print $bulk->Trusting("default"); #prints 1 You may also directly set all values with the integer short cut. $bulk->Trusting(1); # everything is Trusting $bulk->Trusting(0); # nothing is Trusting If you want to specify Trusting in the conf file, you may only directly specify via the integer shortcut. Otherwise, you must use the list equation. # all Trusting Trusting = 1 #none Trusting Trusting = 0 #email is trusting Trusting @= email Trusting @= wrapping This will not work: Trusting = email If you use that syntax, it will internally do: $bulk->Trusting('email'); which you know will only read the value, not set it. If you use the array syntax, it will properly set the value. Note that ->Trusting('default' => 0) is not equivalent to ->Trusting(0). Consider: $bulk->Trusting('email' => 1); print $bulk->Trusting('email'); # prints 1 $bulk->Trusting("default' => 0); print $bulk->Trusting('email'); # still prints 1 $bulk->Trusting(0); print $bulk->Trusting('email'); # now prints 0 Currently, you may set: email - Trusting('email' => 1) will not check for valid email addresses wrapping - Trusting('wrapping' => 1) will not try to wrap the message to reach the 1,000 character per line limit duplicates - Trusting('duplicates' => 1) will not do any duplicates checking (this is the equivalent of allow_duplicates in older versions) banned - Trusting('banned' => 1) will not lowercase the local part of a domain in a banned or duplicates check (this is the opposite of safe_banned in older versions. i.e. $bulk2_05->safe_banned(1) == $bulk_300->Trusting('banned' => 0); It is recommended your conf file be: Trusting @= duplicates Since you're usually better off weeding duplicates out in advance. All other Trusting values are recommended to be false. banned banned stores the list of email addresses and domains that are banned. Only store user@domain.com portions of email addresses, don't try to ban "Jim"<jim@jimandkoka.com>, for instance. Only ban jim@jimandkoka.com banned may be either a coderef, globref, arrayref, or string literal. If a string literal, then Mail::Bulkmail will attempt to open that file (in append mode) as your log: $bulk->banned("/path/to/my/banned.addresses"); If a globref, it is assumed to be an open filehandle in append mode: open (B, ">>/path/to/my/banned.addresses"); $bulk->banned(\*B); files should contain one entry per line, each entry being an email address or a domain. For example: jim@jimandkoka.com jimandkoka.com foo@bar.com bar.com if a coderef, it is assumed to be a function to return your banned list: sub B {return $bannedquery->execute()}; #or whatever your code is $bulk->banned(\&B); The function should return one entry per execution, either an address or a domain. if an arrayref, then it's an array of banned addresses and domains $bulk->banned([qw(jim@jimandkoka.com jimandkoka.com)]); The arrayref can contain email addresses and domains. Use whichever item is most convenient, and Mail::Bulkmail will take it from there. Once banned has been populated, the values are stored internally in a hashref. Precedence Precedence is a validating accessor to validate the Precedence you have passed for your mailing list. Precedence must be either: * list (default) - a mailing list * bulk - bulk mailing of some type * junk - worthless test message. You can use an alternate Precedence if you set Trusting to 0. But seriously, there's *no* reason to do that. Keeping the appropriate precedence will help the servers on the internet route your message as well as the rest of the email out there more efficiently. So don't be a jerk, and leave it as one of those three. This method is known to be able to return: MB001 - invalid precedence Tz Returns the timezone that you're in. You cannot set this value. You'll also never need to worry about it. Date Returns the date that this email is being sent, in valid RFC format. Note that this will be stored in _cached_headers as the date that the first email is sent. Another thing you won't need to worry about. METHODS
FAQ
EXAMPLES#simple mailing with a list called "./list.txt"my $bulk = Mail::Bulkmail->new( "LIST" => "./list.txt", "Subject" => "A test message", "Message" => "This is my test message", "From" => 'me@mydomain.com', "To" => 'somelist@mydomain.com', "Reply-To" => 'replies@mydomain.com' ) || die Mail::Bulkmail->error(); $bulk->bulkmail || die $bulk->error; #same thing, but turning off envelope sending my $bulk = Mail::Bulkmail->new( "LIST" => "./list.txt", "Subject" => "A test message", "Message" => "This is my test message", "From" => 'me@mydomain.com', "Reply-To" => 'replies@mydomain.com', "use_envelope" => 0 ) || die Mail::Bulkmail->error(); $bulk->bulkmail || die $bulk->error; #Small example, with a miniature in memory list my $bulk = Mail::Bulkmail->new( "LIST" => [qw(test@mydomain.com me@mydomain.com test2@mydomain.com)], "Subject" => "A test message", "Message" => "This is my test message", "From" => 'me@mydomain.com', "To" => 'somelist@mydomain.com', "Reply-To" => 'replies@mydomain.com', "Sender" => 'sender@mydomain.com' ) || die Mail::Bulkmail->error(); $bulk->bulkmail || die $bulk->error; #Make sure our error logging is on in a different place, and set up a different server my $server = Mail::Bulkmail::Server->new( 'Smtp' => "smtp.mydomain.com", "Port" => 25 ) || die Mail::Bulkmail::Server->error(); my $bulk = Mail::Bulkmail->new( "LIST" => "./list.txt", "Subject" => "A test message", "Message" => "This is my test message", "From" => 'me@mydomain.com', "To" => 'somelist@mydomain.com', "Reply-To" => 'replies@mydomain.com', "ERRFILE" => '/etc/mb/error.file.txt', "servers" => [$server] #our new server ) || die Mail::Bulkmail->error(); $bulk->bulkmail || die $bulk->error; #Make sure our error logging is on in a different place, and set up a different server #this time, we'll use a dummy server for debugging purposes my $dummy_server = Mail::Bulkmail::DummyServer->new( "dummy_file" => "/etc/mb/dummy.server.output.txt" ) || die Mail::Bulkmail::DummyServer->error(); my $bulk = Mail::Bulkmail->new( "LIST" => "./list.txt", "Subject" => "A test message", "Message" => "This is my test message", "From" => 'me@mydomain.com', "To' => 'somelist@mydomain.com', "Reply-To" => 'replies@mydomain.com', "ERRFILE" => '/etc/mb/error.file.txt', "servers" => [$dummy_server] #our new server, which is a dummy server ) || die Mail::Bulkmail->error(); $bulk->bulkmail || die $bulk->error; #mailing just to one address my $bulk = Mail::Bulkmail->new( "Subject" => "A test message", "Message" => "This is my test message", "From" => 'me@mydomain.com', "Reply-To" => 'replies@mydomain.com', "Sender" => 'sender@mydomain.com' ) || die Mail::Bulkmail->error(); $bulk->mail('test@yourdomain.com') || die $bulk->error; #here, a fun one. Use a coderef as our LIST my $query = "select email, domain from table order by domain"; my $stmt = $dbh->prepare($query) || die; $stmt->execute || die; sub get_list { my $bulk = shift; #we always get our bulkmail object first my $data = $stmt->fetchrow_hashref(); if ($data) { return $data->{"email"}; } else { return undef; }; }; $bulk->LIST(\&get_list); #and now, logging to a coderef. my $query = ('insert into table good_addresses (email) values (?)'); my $stmt = $dbh->prepare($query) || die; sub store_to_db { my $bulk = shift; #always get our bulkmail object first my $email = shift; $stmt->execute($email) || return $bulk->error("Could not store to DB!"); return 1; }; $bulk->GOOD(\&store_to_db); SAMPLE CONFIG FILEThis is my current conf file. It's about as close to one that you want to use as possible. Remember, you can set any values you'd like in the conf file, as long as they're scalars or arrayrefs of scalars. For example, if you want a default "From" value, then define it in the conf file.For more information on conf files, see Mail::Bulkmail::Object. For more information on the server file, see Mail::Bulkmail::Server. This file is also stored in the file "sample.cfg.file" define package Mail::Bulkmail #server_class stores the server object that we're going to use. #uncomment the DummyServer line and comment out the Server line for debugging server_class = Mail::Bulkmail::Server #server_class = Mail::Bulkmail::DummyServer #log our errors ERRFILE = /etc/mb/error.txt BAD = /etc/mb/bad.txt GOOD = /etc/mb/good.txt banned = /etc/mb/banned.txt #if we want a default From value, you can place it here. #From = me@mydomain.com define package Mail::Bulkmail::Server #set up the domain we use to say HELO to our relay Domain = mydomain.com #Most servers are going to connect on port 25, so we'll set this as the default port here Port = 25 #We'll give it 5 tries to connect before we let ->connect fail Tries = 5 #Lets try to reconnect to a server 5 times if ->connect fails. max_connection_attempts = 5 #100 is a good number for the envelope_limit envelope_limit = 100 #Send 1,000 messages to each server in the round before going to the next one. #set max_messages_per_robin to 0 if you're only using one server, otherwise you'll have needless #overhead max_messages_per_robin = 0 #maximum number of messages per connection. Probably best to keep this 0 unless you have a reason #to do otherwise max_messages_per_connection = 0 #maximum number of messages for the server. Probably best to keep this 0 unless you have a reason #to do otherwise max_messages= 0 #maximum number of messages to send before sleeping, probably best to keep this 0 unless you need #to let your server relax and sleep max_messages_while_awake = 0 #sleep for 10 seconds if we're sleeping. This line is commented out because we don't need it. #No harm in uncommenting it, though. #sleep_length = 10 #our list of servers server_file = /etc/mb/servers.txt define package Mail::Bulkmail::Dynamic #it is highly recommended that quotemeta be 1 quotemeta = 1 #set up our default delimiters dynamic_message_delimiter = ; dynamic_message_value_delimiter = = dynamic_header_delimiter = ; dynamic_header_value_delimiter = = #we're going to assume that duplicates have been weeded out, so we'll allow them. Trusting @= duplicates #By default, we'll turn on our envelope. Mail::Bulkmail might as well use it. #Mail::Bulkmail::Dynamic doesn't care about this value. use_envelope = 1 define package Mail::Bulkmail::DummyServer #Our dummy data file, for when we're using DummyServer. It's also useful to send the data to #/dev/null to test things if you don't care about the message output. dummy_file = /etc/mb/dummy.file #dummy_file = /dev/null DIAGNOSTICSBulkmail doesn't directly generate any errors. If something fails, it will return undef and set the ->error property of the bulkmail object. If you've provided an error log file, the error will be printed out to the log file.Check the return of your functions, if it's undef, check ->error to find out what happened. Be warned that isDuplicate and isBanned will return 0 if an address is not a duplicate or banned, respectively, but this is not an error condition. SEE ALSOMail::Bulkmail::Object, Mail::Bulkmail::Server, Mail::Bulkmail::DummyCOPYRIGHT (again)Copyright and (c) 1999, 2000, 2001, 2002, 2003 James A Thomason III (jim@jimandkoka.com). All rights reserved. Mail::Bulkmail is distributed under the terms of the Perl Artistic License.CONTACT INFOSo you don't have to scroll all the way back to the top, I'm Jim Thomason (jim@jimandkoka.com) and feedback is appreciated. Bug reports/suggestions/questions/etc. Hell, drop me a line to let me know that you're using the module and that it's made your life easier. :-)http://www.jimandkoka.com/jim/perl/ for more perl info, http://www.jimandkoka.com in general POD ERRORSHey! The above document had some coding errors, which are explained below:
Visit the GSP FreeBSD Man Page Interface. |