Send a mail to multiple users

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Send a mail to multiple users
# 1  
Old 10-25-2013
Send a mail to multiple users

I have a file 1.txt which has 3 mail ids as below:
Now I want to write a script which will read this file and send the mail to all the users present in this file.
# 2  
Old 10-25-2013
So what have you tried so far?
# 3  
Old 10-25-2013
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"
# 4  
Old 10-25-2013
A bash approach:

while read line
        [[ "$line" =~ "^Maillist" ]] && mail_ids="${line##*=}"

done < 1.txt

mail -s "Subject" "$mail_ids" < mailbody.txt

# 5  
Old 10-25-2013
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.
# 6  
Old 10-25-2013
if each line contains 3 email id then try something like this

while read line
               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"

# 7  
Old 10-26-2013
I think you can add the address list as is as arguments to mail. Read the man page.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a UNIX script to send a mail to the respective individual users about their groups?

Hi Team, I got a requirement to send a mail to the individual users of a unix server about their respective groups. can some one help me to provide the script as I am unable to write that. I tried with below lines but I come out with errors. cat /etc/passwd | awk -F':' '{ print $1}' |... (6 Replies)
Discussion started by: harshabag
6 Replies

2. Shell Programming and Scripting

Mail command --> send multiple attachments

Hi, i try to send two (multiple) files by the mail-console-command mail -s TEST -a f1.pdf f2.pdf but it doesn't work. can someone give me a hint? Thanks in advance, IMPe (2 Replies)
Discussion started by: IMPe
2 Replies

3. Shell Programming and Scripting

Send multiple HTML output in one mail

HI, I have two scripts which is sending the mail in html format. Script 1: 1.IFILE=/home/home01/Report.csv if #Checks if file exists and readable then if awk -F, '{ T += $13 } END { exit(!T) }' ${IFILE} then awk -F, 'BEGIN{ c=split("3,4,8,9,13", col) print "To:... (0 Replies)
Discussion started by: Vivekit82
0 Replies

4. Red Hat

How to send mail with multiple attachments?

We don't have uuencode installed in our machines..... Please tell me how to send mail with multiple attachments ??? URGENT !!!!! Please tell me using command line (or) scripts.......... please...... Thanks in Advance.... (1 Reply)
Discussion started by: vamshigvk475
1 Replies

5. Shell Programming and Scripting

Send e-mail to users

Dear all, The perl script to send e-mail is working in my current script. #This part of the script will send the email notification my $to=''; my $from=''; my $subject='POS_CODES_38 DATA LOADED SUCCESSFULLY.'; my $message='The total no. of files... (2 Replies)
Discussion started by: msrahman
2 Replies

6. Shell Programming and Scripting

How to send mail with multiple files attached?

Hi, I would like to send a mail with multiples files attached. Until now i was doing a "find" and then a "tar" of the text files. As I need to be able to read them on a mobile device such as Blackberry for instance, i would like to send them in one single mail, but without taring them. is... (2 Replies)
Discussion started by: Pierrito
2 Replies

7. AIX

Not able to send out multiple file in mail

Hi All, I have AIX 5.3 server. I am not able to transfer multiple file in mail but I can send one file at a time. the following command I am using to send multiple file mail -s 'PICS EXP RATE Logs' < /data02/transfer/*_experience_rate_log.txt but this not working. i can send... (2 Replies)
Discussion started by: vishalpatel03
2 Replies

8. UNIX for Dummies Questions & Answers

to send email to multiple users

hi, i'm pretty new to this unix. i've been asked to create a shell script which will pick up the email id from a text file(stored in same machine, same directory) searches for that id in another file in which a product name( a one line text) is mentioned against it. then it should send a mail... (0 Replies)
Discussion started by: vishwas.shenoy
0 Replies

9. Shell Programming and Scripting

Using mailx to send email to multiple users.

Hi, I am using the mailx command to send email to multple users. The command works fine when i am sending mail to a single user but when i insert multiple email ids inside the quote it does not work. All the email ids are coming from a property file.Please have a lookt at the property file and... (4 Replies)
Discussion started by: priyaksingh
4 Replies

10. UNIX for Dummies Questions & Answers

How to send mail to multiple users ???

Hi All, How to send mails to multiple users using a single mailx command. Urgently require help Thanks in advance Rgds Arunava (3 Replies)
Discussion started by: arunava_maity
3 Replies
Login or Register to Ask a Question