Simple E-mail Merge

We all know the ‘mail merge’ function that comes with allmost every wordprocessor. You compose one letter you want to send to a group of individuals and their names and addresses are inserted in each letter automatically from a list. I needed such a mail merge for an e-mail I wanted to send. I found that none of the e-mail clients I use supported an ‘e-mail merge’. After some googling I found Tobin Maginnis’ Simple Mail List Shell Script.

This was exactly what I needed. Well, allmost. I needed a slightly more sophisticated approach to name and e-mail management. Also I wanted to be able to insert the subject from the command line instead from the source of the program. So I wrote Simple E-mail Merge (sem). It should run on any posix system. I use msmtp to send the mail via the smtp server of my internet provider.

You invoke sem like this:

sem maillist message "My subject line"

The file ‘maillist’ might look something like:

Larry & Sergey,anothersample@address.comm

The ‘message’ file contains the letter you want to send.

Here’s the code. Please make sure to read my software notice before using this.

# Simple E-mail Merge (sem)
# September 2007
# v.0.4
# by Jeroen Leijen
# based on Tobin Maginnis' Simple Mail List Shell Script
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
# The full text of this software license is at:
# or to receive a written copy of the GNU General Public License, write to
# the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
if [ ${#@} != 3 ]; then
echo "Usage: $0 MailList Letter Subject(in quotes) "
if [[ -e "$1" && -e "$2" ]]; then
echo "Sending $2 with subject $3 to mail list: $1 ..."
while read line ; do
name=`echo $line| cut -d ',' -f 1`
email=`echo $line| cut -d ',' -f 2`
echo "Mailing: $name"
echo "with e-mailaddress: $email"
#You can change 'Dear' in the next line to whatever you need
echo "Dear ${name}," > tempmail$$
cat $2 >> tempmail$$
mail -s "`echo $3`" `echo $email` < tempmail$$
#if you like a bcc copy use this line
#mail -s "`echo $3`" -b your_bcc_address@mail.comm `echo $email` < tempmail$$
done < $1
rm tempmail$$
echo "Finished mail list: $1"
echo "Cannot find mail list file: $1 and/or letter file: $2"

Produce Windows compatible video with OSS (update)

Back in April 2006 I published a short article on how to produce a Microsoft Windows Media Player (MSWMP) compatible video file with open source tools. A few weeks ago I noticed that a file I just converted with my method produced an error during playback in MSWMP.

After some trial and error I found these Mencoder settings to be working:
mencoder name_input_file -oac mp3lame -lameopts preset=64 -ovc lavc -lavcopts vcodec=msmpeg4v2:keyint=5:vbitrate=850:mbd=2:mv0 -ofps 24 -o output_filename.avi

This produces an avi file containing a video compressed with the msmpeg4v2 video codec and the lame mp3 audio codec. It should play with any MSWMP version.

However, if you want to stream this file with a Windows Media streaming server it won’t play. For Windows Media streaming the video has to be put in an asf container instead of an avi container. These Mencoder settings should have done the trick:

mencoder name_input_file -oac mp3lame -lameopts preset=64 -ovc lavc -lavcopts vcodec=msmpeg4v2:keyint=5:vbitrate=850:mbd=2:mv0 -ofps 24 -of lavf -lavfopts format=asf:i_certify_that_my_video_stream_does_not_use_b_frames -o output_filename.asf

But that didn’t work. Maybe Mencoder asf muxing is buggy. I don’t know. Fortunately there are other methods. You can find the VLC solution in my original article. With FFmpeg you can use these settings:

ffmpeg -i name_input_file -vcodec msmpeg4v2 -acodec mp3 -f asf output_filename.asf

More on FFmpeg Windows compatibility can be found here:

I you want to see an example please click below. This video from BBC News (originally in RealVideo, how Ironically) is transcoded with: ffmpeg -i ~/bbc_microsoft.avi -vcodec msmpeg4v2 -acodec mp3 -f asf bbc.asf