On Mon, 3 Jun 2013, Rich Shepard wrote:

On Mon, 20 May 2013, Paul Heinlein wrote:

The tool I'd normally reach for in this situation is m4. If, for instance,
you were able to loop through a list of subscribers and assign
$NAME and $ADDRESS, then

 m4 -D GREETING="$NAME" newsletter.m4 | mail -s "Subject" $ADDRESS

The newletter.m4 would contain the GREETING token which would get replaced
with $NAME.

Paul,

I've read the m4 man page, info file, and manual (the .pdf version of the info file) without seeing how I would set up the input files. I assume that one file contains two tokens, NAME and ADDRESS, but how are they separated on each line?

That was an exercise left to the reader :-) because I don't know how you currently store and retrieve your recipients' e-mail addresses.

If all the file contained was the greeting name and e-mail address, you could separate them anyway you'd like. A CSV format would be easy, but it might break if the greeting name included a comma. A more robust file might use a colon, which is unlikely to occur in your data. Here's a trivial example:

----- %< -----
[email protected]:Bill
[email protected]:PLUG Members
[email protected]:Mr. President
[email protected]:Madam
----- %< -----

For the template, you're correct, e.g.,

----- %< -----
GREETING,

  This is the text of the newsletter.

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
----- %< -----

A script that used those files -- here assumed to be named subscribers.txt and news.m4 -- might work something like this:

while read LINE; do
  ADDR=$(echo $LINE | cut -d: -f1)
  GRTG=$(echo $LINE | cut -d: -f2)
  m4 -D GREETING="$GRTG" news.m4 | mail -s 'June News' $ADDR
done < subscribers.txt

There are, of course, several different ways to accomplish the same task, but that might get you started.

An m4 template, by the way, is easy to construct and test, because by default m4 sends output to /dev/stdout.

--
Paul Heinlein
[email protected]
45°38' N, 122°6' W
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to