|
read from a file to a list
Hello there,
I have a file that contents a list of email address, and each is separated by new lines. I want to read the first email address into TO: filed and the rest into a list and goes to cc field. I plan to use mailx to send the email. I inserted the email addresses into an array, but what can I do to turn the array into a list, so I can pass it to mailx command? The script is working, but it prints list of cc one by one. That won't work for mailx since I need all of them in a list. Thanks!
#read email address line by line, the first line always goes to TO field
fname="/home/.../emailFile.txt"
cc[100]="" #list of cc receipients
exec<$fname
value=0
while read line
do
value=`expr $value + 1`;
if [ $value -eq 1 ]
then
headit=$line
echo "headit email is: $headit" #receipient email address, always the first line in the file
else
cc[$value]=$line
echo "it contacts email: ${cc[$value]}"
fi
done
#mailx command to send email with a text body, attachment, cc, bcc, and replying address,
echo "test" | cat - body.txt | mailx -a attachment.html -b "bcc@mail.com" -c "$cc" -s "test" -r "reply@mail.com" "$headit"
|