Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

E.g. if I want to send a bunch of emails along the lines of "What does it feel like to X?" to ask@qr.ae (Quora allows and even somewhat encourages me to ask highly similar questions there).

And then give a dictionary of words that I want to substitute for X?

I know that the mailx readme has a small section on how to send mail with scripts, but I'm still a UNIX newbie so I'm not sure how I would be able to configure a script in conjunction with mailx just from that.

share|improve this question
up vote 1 down vote accepted

If you mean doing this via shell, then yes this is possible. We may have a different result in mind but the operation is similar to this structure I have written previously to deliver the message via shell.

See: http://www.akamay.net/PUBLIC/massmail.tar

The script uses three (3) files.

  1. Credential File - The actual configuration file. Put it in /tmp

    HEAD_FROM="BSDUSER"                   # Mail from:
    HEAD_TO="${FIELD1[$a]}"             # Rcpt to:
    HEAD_REPLY-TO="info@my.email.com"     # Reply to :)
    HEAD_BCC-TO="i@my.email.com"          # BCC to
    HEAD_SUBJECT="NOTICE - Personalize mass mail for ${FIELD3[$a]}"
    HEAD_PRIORITY="High"                  # Low / Medium / High
    HEAD_IMPORTANCE="3"                   # Importance
    HEAD_MIME-VERSION="1.1"               # MIME Version
    HEAD_CONTENT-TYPE="text/plain"        # Plain or HTML
    TEAM_CONTACT="info@my.email.com"      # Signature @ EOF
    INTERVAL="2"                          # Sleep sec. per send
  2. Owner File - The file containing your FIELD'ed values separated by a ":".

  3. The actual massmail script. The script is simple. What it does is to parse the configuration file using a for loop with the value of the given fields: field1,2,3 etc. What I did is to substitute this values from the CSV file, store it in an executable text with the correct format and pipe everything to sendmail.

    F1=`cat $2 | cut -d: -f1 | perl -ne 'chomp;print" $_"' | sed 's/^[ \t]*//;s/[ \t]*$//'`
    F2=`cat $2 | cut -d: -f2 | perl -ne 'chomp;print" $_"' | sed 's/^[ \t]*//;s/[ \t]*$//'`
    F3=`cat $2 | cut -d: -f3 | perl -ne 'chomp;print" $_"' | sed 's/^[ \t]*//;s/[ \t]*$//'`
    F4=`cat $2 | cut -d: -f4 | perl -ne 'chomp;print" $_"' | sed 's/^[ \t]*//;s/[ \t]*$//'`
    F5=`cat $2 | cut -d: -f5 | perl -ne 'chomp;print" $_"' | sed 's/^[ \t]*//;s/[ \t]*$//'`
    echo -e "#!/bin/bash" > $TMP/notify_exec
    echo -e "FIELD1=($F1)\nFIELD2=($F2)\nFIELD3=($F3)\nFIELD4=($F4)\nFIELD5=($F5)\n" >> $TMP/notify_exec
    echo -e "for ((a=0;a<\${#FIELD1[*]};a++))\ndo" >> $TMP/notify_exec
    echo -e "echo \"From:$C_F" >> $TMP/notify_exec
    echo -e "To:$C_T\nReply-to:$C_RT\nBcc-to:$C_BT\nSubject:$C_S\nPriority:$C_P" >> $TMP/notify_exec
    echo -e "X-Mail-Priority:$C_I\nMime-Version:$C_M\nContent-Type:$C_C\n$C_MSG\n\n\n" >> $TMP/notify_exec
    echo -e "Generated using: $0 - Got questions? E-Mail us at: $C_TM" >> $TMP/notify_exec
    echo -e "\" | /bin/sendmail -t -oi" >> $TMP/notify_exec
    echo -e "sleep $C_SL" >> $TMP/notify_exec
    echo -e "done\nexit 0" >> $TMP/notify_exec
    chmod +x $TMP/notify_exec

I ran into some issues with using mailx regarding the custom reply so I switched with sendmail to deliver the message and it works fine.

share|improve this answer

The Mail Merge extension for Thunderbird should do the trick.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.