.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 .\" .\" Standard preamble: .\" ======================================================================== .de Sh \" Subsection heading .br .if t .Sp .ne 5 .PP \fB\\$1\fR .PP .. .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .\" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .hy 0 .if n .na .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Bulkmail::Dynamic 3pm" .TH Bulkmail::Dynamic 3pm "2008-03-04" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" Mail::Bulkmail::Dynamic \- platform independent mailing list module for mail merges and dynamically built messages .SH "AUTHOR" .IX Header "AUTHOR" Jim Thomason, jim@jimandkoka.com .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 8 \& my $bulk = Mail::Bulkmail::Dynamic\->new( \& "merge_keys" => [qw(BULK_EMAIL name id address city state zip)], \& "merge_delimiter" => "::", \& "LIST" => "~/my.list.txt", \& "From" => "\(aqJim Thomason\(aq", \& "Subject" => "This is a test message", \& "Message" => "Here is my test message" \& ) || die Mail::Bulkmail\->error(); .Ve .PP .Vb 1 \& $bulk\->bulkmail() || die $bulk\->error; .Ve .PP Don't forget to set up your conf file! .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mail::Bulkmail 1.00 had a thing called \*(L"filemapping\*(R", it was to allow you to dynamically populate certain variables into your message. Put in people's names, or the like. .PP 2.00 renamed \*(L"filemapping\*(R" to the correct term \- \*(L"mail merging\*(R", and also added in the ability to dynamically create your message, if so desired. So you could very easily send out completely different messages to everyone on your list, if so desired. But 2.00 also added a *lot* of processing overhead, most of which was unfortunately in the form of voodoo. i.e., I seem to recall lots of testing, debugging, etc. until I finally reached a point where the code worked and I sent it off. Not quite sure how it worked, mind you, but happy with the fact that it worked nonetheless. .PP 3.00 strips that ability out of Mail::Bulkmail, cleans it up, and places it here. This has a few advantages. For one thing, if you're not doing any mailmerging, then you don't have to worry about any of the overhead of building hashes, doing checks, internally handling things, and so on. There wasn't a tremendous amount of useless work done in that case, but it was enough to be noticed. So now use Mail::Bulkmail if you're not doing mail merges, and Mail::Bulkmail::Dynamic if you are. .PP And the other thing is that the code is cleaned up a \fBlot\fR. I actually know and understand how it all works now, and it functions much better than previous versions did. Faster, more efficient, and so on. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .IP "log_all_data" 11 .IX Item "log_all_data" boolean flag, 1/0. .Sp Mail::Bulkmail has an easy job logging its list items \- they're always guaranteed to be single email addresses. Mail::Bulkmail::Dynamic has a harder time, since it's usually an email address and some other data. .Sp .Vb 9 \& \(aqjim@jimandkoka.com::Jim Thomason::24\(aq \& or \& [\(aqjim@jimandkoka.com\(aq, "Jim Thomason", "24"] \& or \& { \& "BULK_EMAIL" => \(aqjim@jimandkoka.com\(aq, \& "name" => "Jim Thomason", \& "age" => "24" \& } .Ve .Sp Most of that is obviously not simple scalar data and needs to be logged differently. If log_all_data is set to 0, then only the email address will be logged and everything is fine. However, if log_all_data is 1, then a hashref containing all of the data is returned (regardless of the type of data structure you initially handed in). Obviously, you will then need to deal with logging yourself, either by logging to an arrayref or (better) to a function call. Logging to a file with log_all_data set to 1 will just give you a useless list of \*(L"\s-1HASH\s0(0x7482)\*(R" and the like. .Sp All pieces may be used simultaneously. So in one mailing, you can use merge_keys, dynamic_message_data, dynamic_header_data, and global_merge. .IP "merge_keys" 11 .IX Item "merge_keys" This should be much easier to use and understand than it was in prior versions. .Sp Okay, let's start off with the simple case, you have a file that contains a list of email addresses: .Sp .Vb 3 \& foo@bar.com \& bob@hope.com \& john@junior.com .Ve .Sp And you set up a list with Mail::Bulkmail to mail to them. Your message is something like this: .Sp .Vb 1 \& "Hi there. Things are great in my world, how\(aqs yours?" .Ve .Sp This works fine for a while, people are happy, everything's dandy. But then, you decide that it would be nice to personalize your email messages in some fashion. So you switch to Mail::Bulkmail::Dynamic. You'll need more information in your list of addresses now. .Sp .Vb 3 \& foo@bar.com::Mr. Foo \& me@there.com::Bob Hope \& john@junior.com::John Jr. .Ve .Sp And then you'll need to define your merge_keys. merge_keys is an arrayref that defines how the data in your file is structured: .Sp .Vb 1 \& merge_keys => [qw(BULK_EMAIL <>)] .Ve .Sp That tells Mail::Bulkmail::Dynamic that the first item in your list is the email address, and the second one is your name. Please note that the email address \fB\s-1MUST\s0\fR be called \*(L"\s-1BULK_EMAIL\s0\*(R", that's the keyword that the module looks for to find the address to send to. The rest of your keys may be named anything you'd like, but avoid naming keys starting with \*(L"\s-1BULK_\s0\*(R", because those are reserved for my use internally and I may add more special keys like that in the future. .Sp (You'll also need to make sure that your merge_delimiter is set to \*(L"::\*(R", see merge_delimiter, below). .Sp Now you can change your message to the following: .Sp .Vb 1 \& "Hi there, <>. Things are great in my world, how\(aqs yours?" .Ve .Sp This will send out the messages, respectively: .Sp .Vb 1 \& Hi there, Mr. Foo. Things are great in my world, how\(aqs yours? .Ve .Sp .Vb 1 \& Hi there, Bob Hope. Things are great in my world, how\(aqs yours? .Ve .Sp .Vb 1 \& Hi there, John Junior. Things are great in my world, how\(aqs yours? .Ve .Sp And voila. Customization. you may include as much data as you'd like: .Sp .Vb 1 \& merge_keys = [qw(<> BULK_EMAIL <> <> <> <>)] .Ve .Sp .Vb 2 \& #in your list: \& Jim Thomason::jim@jimandkoka.com::IL::24::Programming Perl::titanium powerbook .Ve .Sp .Vb 1 \& #and then your message. .Ve .Sp .Vb 3 \& Dear <>, \& How\(aqve you been? I see that your email address is still BULK_EMAIL. \& Are you still living in <>? And you\(aqre still <>, right? .Ve .Sp .Vb 2 \& Do you still enjoy <>? \& Well, email me back a message from your <>. .Ve .Sp And that's all there is to it. Just be sure to remember that any keys you define will get clobbered *anywhere* in the message. .Sp .Vb 2 \& merge_keys => [qw(BULK_EMAIL name)] \& LIST => [qw(jim@jimandkoka.com::Jim)] .Ve .Sp .Vb 1 \& "Hi there, name. I\(aqve always liked your name." .Ve .Sp You *probably* want that message to populate as: .Sp .Vb 1 \& "Hi there, Jim. I\(aqve always liked your name." .Ve .Sp But it will populate as: .Sp .Vb 1 \& "Hi there, Jim. I\(aqve always liked your Jim." .Ve .Sp Which doesn't make sense. So just make sure your keys aren't anywhere else in your message. For example, .Sp .Vb 2 \& merge_keys => [qw(BULK_EMAIL )] \& LIST => [qw(jim@jimandkoka.com::Jim)] .Ve .Sp .Vb 1 \& "Hi there, . I\(aqve always liked your name." .Ve .Sp Your list data may be a delimited scalar, as we've been using in our examples: .Sp .Vb 1 \& jim@jimandkoka.com::Jim::24 .Ve .Sp Or an arrayref: .Sp .Vb 1 \& [\(aqjim@jimandkoka.com\(aq, \(aqJim\(aq, \(aq24\(aq] .Ve .Sp In both of those cases, the order of the data is important. Each data element matches up to a particular key. So be sure that your data is actually in the same order as defined in your merge_keys array. .Sp Alternatively, you can also just store your data in a hash and pass that in: .Sp .Vb 5 \& { \& \(aqBULK_EMAIL\(aq => \(aqjim@jimandkoka.com\(aq, \& \(aq\(aq => \(aqJim\(aq, \& \(aq\(aq => \(aq24\(aq \& } .Ve .Sp This is the one case where your merge_keys values will be ignored, and a mailmerge will be done with the key/value pairs passed in that hashtable. .Sp Passing in a hashtable is the fastest in terms of internal processing, but there may be additional work on your end to generate the hash. When reading from a file, you should always use delimited strings (since that's what'd be in your file anyway), but from other sources you can experiment with hashrefs or arrayrefs and see which is faster for your uses. .Sp mail merges apply to \fBboth\fR message \fBand\fR header information. So it's valid to do: .Sp .Vb 1 \& $dynamic\->Subject("Hello there, "); .Ve .Sp And have the mail merge pick that up. .Sp Note that the merge will be performed in an arbitrary order, independent of what's specified in merge_keys. So don't expect to have one piece of the merge populate into your message before another one. .IP "merge_delimiter" 11 .IX Item "merge_delimiter" If you're reading in from a file, you can't have arrayrefs, hashrefs, whatever. They don't store nicely in text. So your data will probably be a delimited string. In that case, you need to know the delimiter. Set it with merge_delimiter. .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim .Ve .Sp .Vb 2 \& #then \& $dynamic\->merge_delimiter("::"); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com\-+\-Jim .Ve .Sp .Vb 2 \& #then \& $dynamic\->merge_delimiter(\(aq\-+\-\(aq); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com,Jim .Ve .Sp .Vb 2 \& #then \& $dynamic\->merge_delimiter(\(aq,\(aq); .Ve .Sp Just be sure that your delimiting string occurs *only* as the delimiter and is never embedded in your data. No escaping of a delimiter is possible. .IP "global_merge" 11 .IX Item "global_merge" It can be useful to to do a mail merge with non-address specific data. For example, you may want to put today's date in your subject. But it's silly (if not impossible) to populate that data out to all of your addresses. This is where the global_merge comes in. .Sp .Vb 5 \& $dynamic\->global_merge( \& { \& "" => scalar localtime \& } \& ); .Ve .Sp .Vb 1 \& or, at creation: .Ve .Sp .Vb 5 \& my $dynamic = Mail::Bulkmail::Dynamic\->new( \& "global_merge" => { \& "" => scalar localtime \& } \& ); .Ve .Sp <\s-1DATE\s0> will now change to today's date in your message. .Sp .Vb 1 \& "Hello, list member. This is the list for " .Ve .Sp This is a hash table that populates merge data \fBbefore\fR individual mail merge items. There is no way to use the same key for both a global_merge and a per-address merge. The global merge will always pick it up and the individual merge will miss it. So, as always, use different keys. .IP "dynamic_message_data" 11 .IX Item "dynamic_message_data" Mail merges are all well and good, they store unique information about a unique email address. But sometimes you want to group together several users and send them the same information based upon some other criteria. That's where dynamic_message_data comes in handy. .Sp This is probably easiest explained via examples. dynamic_message_data is a hashref of hashrefs, such as this: .Sp .Vb 19 \& $dynamic\->dynamic_message_data( \& { \& \(aq\(aq => { \& \(aqover70\(aq => \(aqnapping\(aq, \& \(aq40\-50\(aq => \(aqamassing wealth\(aq, \& \(aq20\-40\(aq => \(aqworking\(aq, \& \(aqunder20\(aq => \(aqplaying\(aq \& }, \& \(aq\(aq => { \& \(aqhates_animals\(aq => "I see you hate animals.", \& "likes_animals" => "I see you like animals.", \& "loves_animals" => "I see you love animals." \& }, \& \(aq\(aq => { \& \(aqyes\(aq => \(aqHi there, \(aq, \& \(aqno\(aq => \(aqHi there\(aq \& } \& } \& ); .Ve .Sp Now then, your merge keys could be defined as such: .Sp .Vb 1 \& \->merge_keys([qw(BULK_EMAIL BULK_DYNAMIC_MESSAGE)]); .Ve .Sp Your list would be: .Sp .Vb 3 \& foo@bar.com::Mr. Foo::23::=20\-40;=hates_animals;=yes \& me@there.com::Bob Hope::78::=over70;=likes_animals;=no \& john@junior.com::John Jr.::14::=under20;=likes_animals;=yes .Ve .Sp And finally, your message would be: .Sp .Vb 2 \& . Judging by your age, which is , you should enjoy . \& Oh, and .Ve .Sp The messages sent out would be, respectively: .Sp .Vb 2 \& Hi there, Mr. Foo. Judging by your age, which is 23, you should enjoy working. \& Oh, and I see you hate animals. .Ve .Sp .Vb 2 \& Hi there. Judging by your age, which is 78, you should enjoy napping. \& Oh, and I see you like animals. .Ve .Sp .Vb 2 \& Hi there, John Jr.. Judging by your age, which is 14, you should enjoy playing. \& Oh, and I see you like animals. .Ve .Sp See? easy as pie. Your dynamic message should be specified in your merge_keys as \s-1BULK_DYNAMIC_MESSAGE\s0, and should be a delimited string (in this case). .Sp .Vb 1 \& agegroup=20\-40;=hates_animals;=yes .Ve .Sp You can specify what delimiters you'd like to use. In this case, your dynamic_message_delimiter is ';', and your dynamic_message_value_delimiter is '='. .Sp More clearly, this information translates to the following: .Sp .Vb 3 \& => 20\-40 \& => hates_animals \& => yes .Ve .Sp Please note that angle brackets are not required, they're just useful for clarity in our example. This is also perfectly acceptable: .Sp .Vb 10 \& $dynamic\->dynamic_message_data( \& { \& \(aqagegroup\(aq => { \& \(aqover70\(aq => \(aqnapping\(aq, \& \(aq40\-50\(aq => \(aqamassing wealth\(aq, \& \(aq20\-40\(aq => \(aqworking\(aq, \& \(aqunder20\(aq => \(aqplaying\(aq \& } \& } \& ); .Ve .Sp .Vb 1 \& me@there.com::Bob Hope::78::agegroup=over70 .Ve .Sp As long as you use the same keys, you're fine. .Sp So you should be able to easily see that we'll look up the message associated with being in the agegroup of 20\-40, the animallover that hates_animals, and then personilized with a choice of 'yes'. .Sp Dynamic message creation is done before mail merging, so you are more than welcome to put mail merge tokens inside your dynamic message, as we did above with the \*(L"\*(R" token, which may include the mail merge token of \*(L"\*(R". .Sp Don't use the same tokens for mailmerges and dynamic messages, since the system may get confused. .Sp Alternatively, instead of a delimited string, you may pass in an arrayref of strings: .Sp .Vb 1 \& [qw(agegroup=20\-40 =hates_animals =yes)] .Ve .Sp or an arrayref of arrayrefs: .Sp .Vb 1 \& [[qw(agegroup 20\-40)], [qw( hates_animals)], [qw( yes)]] .Ve .Sp or a hashref: .Sp .Vb 5 \& { \& agegroup => 20\-40 \& animallover => hates_animals \& personilized => yes \& } .Ve .Sp Passing in a hashtable is the fastest in terms of internal processing, but there may be additional work on your end to generate the hash. When reading from a file, you should always use delimited strings (since that's what'd be in your file anyway), but from other sources you can experiment with hashrefs or arrayrefs and see which is faster for your uses. .Sp dynamic messages apply to \fBonly\fR message information. use dynamic_header_data for dynamic pieces in headers. .Sp Note that the dynamic message creation will be performed in an arbitrary order. So don't expect to have one piece of the dynamic message populate into your message before another one. .Sp There is one special key for dynamic_message_data, \*(L"_default\*(R". .Sp .Vb 21 \& $dynamic\->dynamic_message_data( \& { \& \(aq\(aq => { \& \(aqover70\(aq => \(aqnapping\(aq, \& \(aq40\-50\(aq => \(aqamassing wealth\(aq, \& \(aq20\-40\(aq => \(aqworking\(aq, \& \(aqunder20\(aq => \(aqplaying\(aq, \& \(aq_default\(aq => \(aqYou have not specified an age group\(aq \& }, \& \(aq\(aq => { \& \(aqhates_animals\(aq => "I see you hate animals.", \& "likes_animals" => "I see you like animals.", \& "loves_animals" => "I see you love animals.", \& "_default" => "I don\(aqt know how you feel about animals" \& }, \& \(aq\(aq => { \& \(aqyes\(aq => \(aqHi there, \(aq, \& \(aqno\(aq => \(aqHi there\(aq, \& } \& } \& ); .Ve .Sp It should be fairly obvious \- if that key is not specified, then the _default value is used. Using our earlier example, with the following list: .Sp .Vb 1 \& foo@bar.com::Mr. Foo::23::=20\-40 .Ve .Sp And the same message of: .Sp .Vb 2 \& . Judging by your age, which is , you should enjoy . \& Oh, and .Ve .Sp The messages sent out would be, respectively: .Sp .Vb 2 \& . Judging by your age, which is 23, you should enjoy working. \& Oh, and I don\(aqt know how you feel about animals. .Ve .Sp Note that since was specified, we used that value. Since was not specified, the default was used, and since was not specified and has no default, it was simply wiped out. .IP "dynamic_message_delimiter" 11 .IX Item "dynamic_message_delimiter" If you're reading in from a file, you can't have arrayrefs, hashrefs, whatever. They don't store nicely in text. So your data will probably be a delimited string. In that case, you need to know the delimiter. Set it with dynamic_message_delimiter. Note that your dynamic message data is just an entry in your merge data. We'll assume a merge_delimiter of '::' and a dynamic_message_value_delimiter of '=' for these examples .Sp .Vb 1 \& \->merge_keys([qw(BULK_EMAIL BULK_DYNAMIC_MESSAGE)]); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::agegroup=20\-40;animallover=yes .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_delimiter(";"); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::agegroup=20\-40&animallover=yes .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_delimiter(\(aq&\(aq); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::agegroup=20\-40,,animallover=yes .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_delimiter(\(aq,,\(aq); .Ve .Sp Just be sure that your delimiting string occurs *only* as the delimiter and is never embedded in your data. No escaping of a delimiter is possible. .IP "dynamic_message_value_delimiter" 11 .IX Item "dynamic_message_value_delimiter" If you're reading in from a file, you can't have arrayrefs, hashrefs, whatever. They don't store nicely in text. So your data will probably be a delimited string. In that case, you need to know the delimiter. Set it with dynamic_message_delimiter. Note that your dynamic message data is just an entry in your merge data. We'll assume a merge_delimiter of '::' and a dynamic_message_delimiter of ';' for these examples .Sp .Vb 1 \& \->merge_keys([qw(BULK_EMAIL BULK_DYNAMIC_MESSAGE)]); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::agegroup=20\-40;animallover=yes .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_value_delimiter("="); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::agegroup:=20\-40;animallover:=yes .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_value_delimiter(\(aq:=\(aq); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::agegroup\-\-20\-40;animallover\-\-yes .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_value_delimiter(\(aq\-\-\(aq); .Ve .Sp Just be sure that your delimiting string occurs *only* as the delimiter and is never embedded in your data. No escaping of a delimiter is possible. .IP "dynamic_header_data" 11 .IX Item "dynamic_header_data" Mail merges are all well and good, they store unique information about a unique email address. But sometimes you want to group together several users and send them the same information based upon some other criteria. That's where dynamic_message_data comes in handy. dynamic_header_data is virtually identical to dynamic_message_data in terms of behavior, but it operates on the message header instead of the message instelf. .Sp This is probably easiest explained via examples. dynamic_header_data is a hashref of hashrefs, such as this: .Sp .Vb 19 \& $dynamic\->dynamic_header_data( \& { \& \(aqSubject\(aq => { \& \(aqpolite\(aq => "Hello, sir", \& "impolite" => "Hello", \& "rude" => "Hey, jerk\-off" \& }, \& \(aqReply\-To\(aq => { \& \(aquseful\(aq => \(aqreturn@myaddress.com\(aq, \& \(aqsemiuseful\(aq => \(aqfilteredreturn@myaddress.com\(aq, \& \(aquseless\(aq => \(aqnowhere@noemail.com\(aq \& }, \& \(aqX\-Type\(aq => { \& \(aqpremium\(aq => "All Services are available", \& "gold" => "Most servies are available", \& "none" => "No services are available" \& } \& } \& ); .Ve .Sp Now then, your merge keys could be defined as such: .Sp .Vb 1 \& \->merge_keys([qw(BULK_EMAIL BULK_DYNAMIC_MESSAGE BULK_DYNAMIC_HEADERS)]); .Ve .Sp Your list would be: .Sp .Vb 3 \& foo@bar.com::Mr. Foo::23::agegroup=20\-40;animallover=hates_animals;personalized=yes::Subject=polite;Reply\-To:useful;X\-Type:gold \& me@there.com::Bob Hope::78::agegroup=over70;animallover=likes_animals;personalized=no::Subject=rude;Reply\-To:useful;X\-Type:premium \& john@junior.com::John Jr.::14::agegroup=under20;animallover=likes_animals;personalized=yes::Subject=impolite;Reply\-To:useless;X\-Type:none .Ve .Sp The messages sent out would have the following headers, respectively: .Sp .Vb 3 \& Subject : Hello, sir \& Reply\-To: return@myaddress.com \& X\-Type : Most services are available .Ve .Sp .Vb 3 \& Subject : Hey, jerk\-off \& Reply\-To: return@myaddress.com \& X\-Type : All Services are available .Ve .Sp .Vb 3 \& Subject : Hello \& Reply\-To: nowhere@noemail.com \& X\-Type : No services are available .Ve .Sp See? easy as pie. Your dynamic headers should be specified in your merge_keys as \s-1BULK_DYNAMIC_HEADERS\s0, and should be a delimited string (in this case). .Sp Subject=polite;Reply\-To=useful;X\-Type=gold .Sp You can specify what delimiters you'd like to use. In this case, your dynamic_header_delimiter is ';', and your dynamic_header_value_delimiter is '='. .Sp More clearly, this information translates to the following: .Sp .Vb 3 \& Subject => polite \& Reply\-To => useful \& X\-Type => gold .Ve .Sp Note that unlike dynamic_message_data, the key in this case is not used to substitute out a string in your headers (or message), the key is used to name the header that is appended on the message. .Sp Dynamic header creation is done before mail merging, so you are more than welcome to put mail merge tokens inside your dynamic headers. .Sp Don't use the same tokens for mailmerges and dynamic headers, since the system may get confused. .Sp Alternatively, instead of a delimited string, you may pass in an arrayref of strings: .Sp .Vb 1 \& [qw(Subject=polite Reply\-To=useful X\-Type:gold)] .Ve .Sp or an arrayref of arrayrefs: .Sp .Vb 1 \& [[qw(Subject polite)], [qw(Reply\-To useful)], [qw(X\-Type gold)]] .Ve .Sp or a hashref: .Sp .Vb 5 \& { \& Subject => polite \& Reply\-To => useful \& X\-Type => gold \& } .Ve .Sp Passing in a hashtable is the fastest in terms of internal processing, but there may be additional work on your end to generate the hash. When reading from a file, you should always use delimited strings (since that's what'd be in your file anyway), but from other sources you can experiment with hashrefs or arrayrefs and see which is faster for your uses. .Sp dynamic headers apply to \fBonly\fR header information. use dynamic_message_data for dynamic pieces in messages. .Sp Note that the dynamic header creation will be performed in an arbitrary order. So don't expect to have one piece of the dynamic header populate into your message before another one. .Sp There is one special key for dynamic_header_data, \*(L"_default\*(R". .Sp .Vb 21 \& $dynamic\->dynamic_message_data( \& { \& \(aqSubject\(aq => { \& \(aqpolite\(aq => "Hello, sir", \& "impolite" => "Hello", \& "rude" => "Hey, jerk\-off", \& \(aq_default\(aq => "Default subject", \& }, \& \(aqReply\-To\(aq => { \& \(aquseful\(aq => \(aqreturn@myaddress.com\(aq, \& \(aqsemiuseful\(aq => \(aqfilteredreturn@myaddress.com\(aq, \& \(aquseless\(aq => \(aqnowhere@noemail.com\(aq, \& \(aq_default" => \(aqreply@to.com\(aq \& }, \& \(aqX\-Type\(aq => { \& \(aqpremium\(aq => "All Services are available", \& "gold" => "Most servies are available", \& "none" => "No services are available" \& } \& } \& ); .Ve .Sp Behavior is similar to that of _default in dynamic_message_data. If a header is specified, it is used. If no value is specified, it will attempt to use the _default value. But, in this case, if there is no value passed and no default, then the header just won't be set. Unless it is one of the speciality headers, such as From. In that case, it will attempt a specific dynamic_message_data value for From, then the \&\*(L"_default\*(R" value in dynamic_message_data for from, and then finally the \->From value itself. .Sp If there's a header specified in \->dynamic_header_data, it will be preferred to use over one set via \->header. .Sp i.e., the order that a header will be checked is: .Sp .Vb 4 \& 1) Is there a specific header key for the header? (Subject => polite) \& 2) Is there a default header key for the header? (Subject => _default) \& 3) Is this a specialty header (i.e., \->From), and is that set? ($bulk\->From()) \& 4) Is there a generic, non\-dynamic header set? (\->header(\(aqFoo\(aq)) .Ve .Sp Headers will not be set more than once, no matter how many places you specify them. .IP "dynamic_header_delimiter" 11 .IX Item "dynamic_header_delimiter" If you're reading in from a file, you can't have arrayrefs, hashrefs, whatever. They don't store nicely in text. So your data will probably be a delimited string. In that case, you need to know the delimiter. Set it with dynamic_header_delimiter. Note that your dynamic header data is just an entry in your merge data. We'll assume a merge_delimiter of '::' and a dynamic_header_value_delimiter of '=' for these examples .Sp .Vb 1 \& \->merge_keys([qw(BULK_EMAIL BULK_DYNAMIC_HEADERS)]); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::Subject=polite;Reply\-To=useful .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_delimiter(";"); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::Subject=polite&Reply\-To=useful .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_delimiter(\(aq&\(aq); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::Subject=polite,,Reply\-To=useful .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_delimiter(\(aq,,\(aq); .Ve .Sp Just be sure that your delimiting string occurs *only* as the delimiter and is never embedded in your data. No escaping of a delimiter is possible. .IP "dynamic_header_value_delimiter" 11 .IX Item "dynamic_header_value_delimiter" If you're reading in from a file, you can't have arrayrefs, hashrefs, whatever. They don't store nicely in text. So your data will probably be a delimited string. In that case, you need to know the delimiter. Set it with dynamic_header_delimiter. Note that your dynamic header data is just an entry in your merge data. We'll assume a merge_delimiter of '::' and a dynamic_header_delimiter of ';' for these examples .Sp .Vb 1 \& \->merge_keys([qw(BULK_EMAIL BULK_DYNAMIC_HEADERS)]); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::Subject=polite;Reply\-To=useful .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_value_delimiter("="); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::Subject:=polite;Reply\-To:=useful .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_value_delimiter(\(aq:=\(aq); .Ve .Sp .Vb 2 \& #in your list \& jim@jimandkoka.com::Jim::Subject\-\-polite;Reply\-To\-\-useful .Ve .Sp .Vb 2 \& #then \& $dynamic\->dynamic_message_value_delimiter(\(aq\-\-\(aq); .Ve .Sp Just be sure that your delimiting string occurs *only* as the delimiter and is never embedded in your data. No escaping of a delimiter is possible. .IP "quotemeta" 11 .IX Item "quotemeta" boolean flag. 1/0 .Sp While mailmerging, you can specify keys that would contain regex meta data. .Sp For example: .Sp .Vb 1 \& \->merge_keys [qw(*name* BULK_EMAIL)] .Ve .Sp Would generate an error, because the * character has special meaning to a regex. With quotemeta turned on, you can use that as a token because it will be quoted when used in the regex. .Sp It is \fBhighly\fR recommended that you leave quotemeta set to 1. Set it to 0 only if you really know what you're doing. .IP "use_envelope" 11 .IX Item "use_envelope" In this subclass, use_envelope is a method that will always return 0. .Sp For Dynamic messages, it's impossible to use the envelope. Sorry, gang, if you want to use mail merges, then you can't use the added speed that the envelope provides you with. .Sp And it only makes sense, because envelope sending sends the exact same message to multiple people. If you're doing a mail merge, then you're customizing each message, so it wouldn't make sense to send that thing to multiple people. .Sp For raw speed, use Mail::Bulkmail and use_envelope => 1. For mail merges, use this. .SH "METHODS" .IX Header "METHODS" .IP "extractEmail" 11 .IX Item "extractEmail" extractEmail is an overridden method from Mail::Bulkmail. Most of the time when you're in Mail::Bulkmail::Dynamic, the data structure that's passed around internally is a hashref, and the email address is at the key \s-1BULK_EMAIL\s0. .Sp This extracts that key and returns it. Again, this method is used internally and is not something you need to worry about. .Sp This method is known to be able to return: .Sp .Vb 1 \& MBD001 \- no BULK_EMAIL defined .Ve .IP "extractSender" 11 .IX Item "extractSender" extractSender is an overridden method from Mail::Bulkmail. Most of the time when you're in Mail::Bulkmail::Dynamic, the data structure that's passed around internally is a hashref, and the sender is at the key \s-1BULK_SENDER\s0. .Sp This extracts that key and returns it. Again, this method is used internally and is not something you need to worry about. .Sp This method is known to be able to return: .Sp .Vb 1 \& MBD015 \- no BULK_SENDER defined .Ve .IP "extractReplyTo" 11 .IX Item "extractReplyTo" extractReplyTo is an overridden method from Mail::Bulkmail. Most of the time when you're in Mail::Bulkmail::Dynamic, the data structure that's passed around internally is a hashref, and the email address is at the key \s-1BULK_REPLYTO\s0. .Sp This extracts that key and returns it. Again, this method is used internally and is not something you need to worry about. .Sp This method is known to be able to return: .Sp .Vb 1 \& MBD016 \- no BULK_REPLYTO defined .Ve .IP "buildHeaders" 11 .IX Item "buildHeaders" Another overridden method from Mail::Bulkmail. This one constructs headers and also includes any dynamic headers, if they have been specified in \s-1BULK_DYNAMIC_HEADERS\s0. .Sp And, finally, it will do a mail merge on all headers (first global, then individual). .Sp Still called internally and still something you don't need to worry about. .Sp This \->buildHeaders cannot accept the optional second headers_hash parameter .Sp This method is known to be able to return: .Sp .Vb 2 \& MBD013 \- cannot bulkmail w/o From \& MBD014 \- cannot bulkmail w/o To .Ve .IP "buildMessage" 11 .IX Item "buildMessage" Another overridden method from Mail::Bulkmail. This one constructs the message and also includes any dynamic message content, if it has been specified in \s-1BULK_DYNAMIC_MESSAGE\s0. .Sp And, finally, it will do a mail merge on the message (first global, then individual). .Sp Still called internally and still something you don't need to worry about. .Sp This method is known to be able to return: .Sp .Vb 1 \& MBD012 \- cannot build message w/o message .Ve .IP "preprocess" 11 .IX Item "preprocess" Overridden from Mail::Bulkmail, preprocesses the data returned from getNextLine($bulk\->\s-1LIST\s0) and makes sure that Mail::Bulkmail::Dynamic knows how to work with it. Constructs the internal data structures to handle mail merges, dynamic messages, and dynamic headers, for any of those items that are in use. .Sp Still called internally and still not something you need to worry about. .IP "buildMessageHash" 11 .IX Item "buildMessageHash" Given a delimited string, arrayref, or hashref, formats it according to the information contained in merge_keys and returns it. .Sp Called internally, and not something you should worry about. .Sp This method is known to be able to return: .Sp .Vb 3 \& MBD002 \- no merge_delimiter \& MBD003 \- different number of keys and values \& MBD004 \- cannot bulid merge hash .Ve .IP "buildDynamicMessageHash" 11 .IX Item "buildDynamicMessageHash" Given a delimited string, arrayref, or hashref, formats it according to the information contained in dynamic_message_data and returns it. .Sp Called internally, and not something you should worry about. .Sp This method is known to be able to return: .Sp .Vb 4 \& MBD005 \- cannot split w/o dynamic_message_delimiter \& MBD006 \- cannot split w/o dynamic_message_value_delimiter \& MBD007 \- invalid dynamic message key \& MBD008 \- cannot build dynamic message hash .Ve .IP "buildDynamicHeaderHash" 11 .IX Item "buildDynamicHeaderHash" Given a delimited string, arrayref, or hashref, formats it according to the information contained in dynamic_header_data and returns it. .Sp Called internally, and not something you should worry about. .Sp This method is known to be able to return: .Sp .Vb 4 \& MBD008 \- cannot split w/o dynamic_header_delimiter \& MBD009 \- cannot split w/o dynamic_header_value_delimiter \& MBD010 \- invalid dynamic header key \& MBD011 \- cannot build dynamic header hash .Ve .IP "convert_to_scalar" 11 .IX Item "convert_to_scalar" convert_to_scalar is still used exclusively internally here, and you still don't need to worry about it. The difference is that this time, our data passed in is not just a simple email address \- it's a hash. If log_all_data is set to true, then you get back the data in the form that you had originally passed it, arrayref, hashref, or delimited string. .Sp Alternatively, the user can decide to just log the email address, if the dynamic and merge information are not important. .SH "EXAMPLES" .IX Header "EXAMPLES" #simple mailing with a list called \*(L"./list.txt\*(R". Note that this is inefficient, since we're not merging we #could just use Mail::Bulkmail instead. .PP .Vb 7 \& my $bulk = Mail::Bulkmail::Dynamic\->new( \& "LIST" => "./list.txt", \& "Subject" => "A test message", \& "Message" => "This is my test message", \& "From" => \(aqme@mydomain.com\(aq, \& "Reply\-To" => \(aqreplies@mydomain.com\(aq \& ) || die Mail::Bulkmail::Dynamic\->error(); .Ve .PP .Vb 1 \& $bulk\->bulkmail || die $bulk\->error; .Ve .PP #simple merge example. Assume that this is your list file: .PP .Vb 3 \& test1@yourdomain.com::Person #1 \& test2@yourdomain.com::Person #2 \& test3@yourdomain.com::Person #3 .Ve .PP .Vb 8 \& my $bulk = Mail::Bulkmail::Dynamic\->new( \& "LIST" => "./list.txt", \& "Subject" => "A test message", \& "Message" => "This is my test message just for you. And your name is NAME.", \& "From" => \(aqme@mydomain.com\(aq, \& "Reply\-To" => \(aqreplies@mydomain.com\(aq, \& "merge_keys" => [qw(BULK_EMAIL NAME)] \& ) || die Mail::Bulkmail::Dynamic\->error(); .Ve .PP .Vb 1 \& $bulk\->bulkmail || die $bulk\->error; .Ve .PP #simple dynamic message example. Assume that this is your list file: .PP .Vb 3 \& test1@yourdomain.com::Person #1::personal_message=mess1 \& test2@yourdomain.com::Person #2::personal_message=mess2 \& test3@yourdomain.com::Person #3::personal_message=mess3 .Ve .PP .Vb 15 \& my $bulk = Mail::Bulkmail::Dynamic\->new( \& "LIST" => "./list.txt", \& "Subject" => "A test message", \& "Message" => "This is my test message. And here\(aqs something personalized for you : personal_message", \& "From" => \(aqme@mydomain.com\(aq, \& "Reply\-To" => \(aqreplies@mydomain.com\(aq, \& "merge_keys" => [qw(BULK_EMAIL NAME)], \& "dynamic_message_data" => { \& "message" => { \& "mess1" => "Greetings, NAME", \& "mess2" => "Hello there, "NAME", \& "mess3" => "Hiya, NAME" \& } \& } \& ) || die Mail::Bulkmail::Dynamic\->error(); .Ve .PP .Vb 1 \& $bulk\->bulkmail || die $bulk\->error; .Ve .PP #simple dynamic message example with two dynamic components. Assume that this is your list file: .PP .Vb 3 \& test1@yourdomain.com::Person #1::personal_message=mess1;addendum=one \& test2@yourdomain.com::Person #2::personal_message=mess2;addendum=two \& test3@yourdomain.com::Person #3::personal_message=mess3;addendum=three .Ve .PP .Vb 20 \& my $bulk = Mail::Bulkmail::Dynamic\->new( \& "LIST" => "./list.txt", \& "Subject" => "A test message", \& "Message" => "This is my test message. And here\(aqs something personalized for you : personal_message. addendum", \& "From" => \(aqme@mydomain.com\(aq, \& "Reply\-To" => \(aqreplies@mydomain.com\(aq, \& "merge_keys" => [qw(BULK_EMAIL NAME)], \& "dynamic_message_data" => { \& "message" => { \& "mess1" => "Greetings, NAME", \& "mess2" => "Hello there, "NAME", \& "mess3" => "Hiya, NAME" \& }, \& \(aqaddendum\(aq => { \& \(aqone\(aq => \(aqYou have received addendum #1\(aq, \& \(aqtwo\(aq => "You\(aqre getting addendum number two", \& "three" => "3 is what you get" \& } \& } \& ) || die Mail::Bulkmail::Dynamic\->error(); .Ve .PP .Vb 1 \& $bulk\->bulkmail || die $bulk\->error; .Ve .PP #simple dynamic message example with a dynamic message, and a dynamic header component. Assume that this is your list file: .PP .Vb 3 \& test1@yourdomain.com::Person #1::personal_message=mess1;addendum=one::Subject=subject1 \& test2@yourdomain.com::Person #2::personal_message=mess2;addendum=two::Subject=subject1 \& test3@yourdomain.com::Person #3::personal_message=mess3;addendum=three::Subject=subject3 .Ve .PP .Vb 27 \& my $bulk = Mail::Bulkmail::Dynamic\->new( \& "LIST" => "./list.txt", \& "Subject" => "A test message", \& "Message" => "This is my test message. And here\(aqs something personalized for you : personal_message. addendum", \& "From" => \(aqme@mydomain.com\(aq, \& "Reply\-To" => \(aqreplies@mydomain.com\(aq, \& "merge_keys" => [qw(BULK_EMAIL NAME)], \& "dynamic_message_data" => { \& "message" => { \& "mess1" => "Greetings, NAME", \& "mess2" => "Hello there, "NAME", \& "mess3" => "Hiya, NAME" \& }, \& \(aqaddendum\(aq => { \& \(aqone\(aq => \(aqYou have received addendum #1\(aq, \& \(aqtwo\(aq => "You\(aqre getting addendum number two", \& "three" => "3 is what you get" \& } \& }, \& "dynamic_header_data" => { \& "Subject" => { \& "subject1" => "you\(aqre getting test message #1", \& "subject2" => "you\(aqre getting test message #2", \& "subject3" => "you\(aqre getting test message #3" \& } \& } \& ) || die Mail::Bulkmail::Dynamic\->error(); .Ve .PP .Vb 1 \& $bulk\->bulkmail || die $bulk\->error; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mail::Bulkmail, Mail::Bulkmail::Server .SH "COPYRIGHT (again)" .IX Header "COPYRIGHT (again)" Copyright and (c) 1999, 2000, 2001, 2002, 2003 James A Thomason \s-1III\s0 (jim@jimandkoka.com). All rights reserved. Mail::Bulkmail::Dynamic is distributed under the terms of the Perl Artistic License. .SH "CONTACT INFO" .IX Header "CONTACT INFO" So 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. :\-)