I have a file 1.txt which has 3 mail ids as below:
Maillist=abc@gmail.com def@gmail.com rcg@gmail.com
Now I want to write a script which will read this file and send the mail to all the users present in this file.
I have a file 1.txt which has 3 mail ids as below:
Maillist=abc@gmail.com def@gmail.com rcg@gmail.com
Now I want to write a script which will read this file and send the mail to all the users present in this file.
So what have you tried so far?
I know the mail command to send the mail to one user.
But i am not sure how to rad a file having multiple mail ids and then send the mail to all thise mail ids present in that file.
cat mailbody.txt | mail -s "abc" abc.gmail.com
A bash approach:
#!/bin/bash
while read line
do
[[ "$line" =~ "^Maillist" ]] && mail_ids="${line##*=}"
done < 1.txt
mail -s "Subject" "$mail_ids" < mailbody.txt
Can we use some approach where we grep the keyword Maillist= and use cut command to delete everything except mail ids and then send the mail..
Something like below:
Email=`grep "MailList=" /1.txt | cut -f2 -d=`;
mail -s "Subject" "$Email" < mailbody.txt
But above is not working.
if each line contains 3 email id then try something like this
#!/bin/bash
while read line
do
IFS='= ' read f1 f2 f3 f4<<<"$line"
echo $f2 $f3 $f4
mail -s "Hello" $f2
mail -s "Hello" $f3
mail -s "Hello" $f4
done <"1.txt"
I think you can add the address list as is as arguments to mail. Read the man page.