Bash – Sending mail to multiple addresses does not work

bashemail

I'm trying to setup a post-commit hook on SVN to send mail to a bunch of users using bash scripts. I have successfully setup the hook and it works when only one email address is specified. But when more email addresses are added no mail arrives. The bash scripts are as follows:

post-commit:

#!/bin/sh
REPOS="$1"
REV="$2"
SENDTO="address1@domain.com, address2@domain.com"

# Send it to these people, calling the script we created above
/home/www/svn/bin/svn_email_commit.sh "$REPOS" "$REV" "$SENDTO"

svn_email_commit.sh:

#!/bin/bash
REPOS=$1
REV=$2
SENDTO=$3
SENDFROM=svn@audioaffair.co.uk

LIMITDIFF=200

# Do various other stuff and dump mail body to a temp file $TMPFILE...

# Send email
/bin/cat $TMPFILE | /bin/mail -s "$SUBJECT" "$SENDTO"

The problem is that /bin/cat $TMPFILE | /bin/mail -s "$SUBJECT" "$SENDTO"
does not work if there are multiple $SENDTO addresses. It works when there is only one address.

I'm on CentOS 5.7

Best Answer

Get rid of the space after the comma:

SENDTO="address1@domain.com,address2@domain.com"

If that doesn't work try just using sendmail. Something like this:

TMPFILE="/var/tmp/email_test"
EMAIL_SUB = "Subject: Your subject";
EMAIL_TO = "To: address1@domain.com, address2@domain.com";
EMAIL_BCC = "Bcc: address3@domain.com";
echo "$EMAIL_TO" >> ${TMPFILE}
echo "$EMAIL_SUB" >> ${TMPFILE}
echo "$EMAIL_BCC" >> ${TMPFILE}
/usr/lib/sendmail -t < ${TMPFILE}