How can i send mail to multiple addresses in same domain in bash?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can i send mail to multiple addresses in same domain in bash?
# 1  
Old 04-28-2009
How can i send mail to multiple addresses in same domain in bash?

Suppose i have a txt file that is the list of the addresses,something like:

lala0045 john james
lala0234 george james

and i want to send an email to lala0045@blabla.com and lala0234@blabla.com,the same domain...what is the exact syntax i should use in my script?
there is a command system(???) but i dont know how to use that...
i have tried a syntax i found using mail,mailx,mailto but no result occured...
any ideas?
# 2  
Old 04-28-2009
Bug mail -s

Please try:
Code:
mail -s "<subject>" "<delivery list>" "matter"

example:
Code:
mail -s "my subject" "id1@c.com id2@c.com id3@c.com" "Hey! i m mailing u all"

try this as hard coded first, then v ll get ur address automatically. Check if the mail comes. Currently m not on a UNIX system so u ll have to try it and let me know if it worked for u unless somebody else provides the complete solution.

Regards,
Hkansal
# 3  
Old 04-28-2009
A really dirty solution but will get you going is :-

Code:
#!/bin/bash

file="inputfile"
domain="blahblah.com"

for local in $(awk '{print $1}' <$file)
do
        address_list="$address_list $local@$domain"
done

echo "address list is [$address_list]"

echo "Hello this is body of the email" | mailx -s "Subject" $address_list

Obviously that doesn't do any variable checking or anything.

If you want to code it with checks you may find this reg ex useful i spent ages doing the other day to validate a space separated email list. Just be aware its not totally rfc compliant as only accepts -_ as special characters and not the full range you should.

Code:
if [ -n $(echo $address_list | awk '/^(\ )*([A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*@([A-Za-z0-9_-]+\.)+[A-Za-z]+((\ )+[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*@([A-Za-z0-9_-]+\.)+[A-Za-z]+)*)(\ )*$/ {print}')" ];then
       # Valid email list
       mailx -s "subject" $address_list < ./email_contents
else
       # Email list problem
       echo "WARNING: Email address list problem [ $address_list ]"
       ....other stuff....
fi

# 4  
Old 04-28-2009
You can use a mail alias in /etc/aliases, then just send the mail to the alias:

Code:
 # cat /etc/aliases
 maillist: user1@blah.com,user2@blah.com,user3@blah.com

When you send mail to maillist, user1, user2, and user3 will all get it.

Quick edit: maillist can be any name.
# 5  
Old 04-28-2009
thank you very much for your answers.i wanted to tell you that i have a bunch of files that contain the first half of the address(that is without the @domain part)so ,each time one of these files is opened, a different first part is read.the domain is the only thing that remains the same.so i need the syntax of the mail command that reads addresses from the fisrt column of a file and then attaches the '@domain' part.thank you again very muchSmilie

//my mistake.didn't have mail installed on my ubuntu.so Ιavascript i tried yours which is closer to what i want to do,but although it doesn't have any mistake i see no email on my mailbox(i send to my self in that domain in order to check the algorithm)...

Last edited by bashuser2; 04-28-2009 at 12:39 PM..
# 6  
Old 04-28-2009
That may be your mail gateway or server mail settings.

Just try this to start with from command line before any scripting.

# echo "Mail test" | mailx -s "Mail Subject" <your_email@address.com>

Obviously removing the < > brackets.

Try typing mailq to see if mail is queued. Also have you configured your mail software on the server to work?

Cheers
# 7  
Old 04-28-2009
Quote:
Originally Posted by lavascript
That may be your mail gateway or server mail settings.

Just try this to start with from command line before any scripting.

# echo "Mail test" | mailx -s "Mail Subject" <your_email@address.com>

Obviously removing the < > brackets.

Try typing mailq to see if mail is queued. Also have you configured your mail software on the server to work?

Cheers
actually the only thing i have done as far as mail is concerned,is to install mailx on my ubuntu...Smilie

//tried this from my command line but still no result in my inbox...

when i type mailq it says 'eximSmilieermission denied'...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bold text in Bash and send mail

I have a sample script here I want to bold the word BOLD in the text and send through email. Tried several ways but not seems to working. BODY="Hello. I want to BOLD this" { echo "From: from@gmail.com" echo "To: to@gmail.com" echo "Subject: Texting" ... (1 Reply)
Discussion started by: lpoolfc
1 Replies

2. UNIX for Dummies Questions & Answers

Configure sendmail to Only send mail to one domain

On both Solaris 10 and RHEL, we would like to configure sendmail in such a way that the email sent from the server should only go to a particular domain. For eg. We want our server to ONLY send the mail to <user_name>@abc.com. All other domains should be blocked/restricted. The server should not... (0 Replies)
Discussion started by: sk2code
0 Replies

3. Shell Programming and Scripting

Send a mail to multiple users

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. (6 Replies)
Discussion started by: Vivekit82
6 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

Perl - match e-mail addresses in multiple files

Hi, I'm trying to write a script that will check multiple files in a directory (all the relevant filenames begin "TT04.NOTES") for e-mail addresses, and then print these addresses to screen with a count at the bottom. I'm a bit of a novice with Perl but thought it would be the best tool for the... (2 Replies)
Discussion started by: wf1974
2 Replies

6. AIX

I Need to send mail to 2 domain

Hi, I need to send alert mail from AIX to mail server. My mail server IP is 192.168.0.10 so I've add /etc/hosts as below 192.168.0.10 mydomain1.com the I try to send mail to myname@mydomain1.com it's OK Then I need to send mail to myname@mydomain2.com too. so I've... (1 Reply)
Discussion started by: oakmojo
1 Replies

7. Shell Programming and Scripting

Echo - Sending mail to multiple addresses

Hi, If I want my script to send a mail to multiple recipients I can do the following: if then echo $err_string1 | mailx -s "UAT CPU ALERT" 1@email.com echo $err_string1 | mailx -s "UAT CPU ALERT" 2@email.com fi Can this also be done something like: ... (1 Reply)
Discussion started by: runnerpaul
1 Replies

8. Shell Programming and Scripting

bash, ssh and expect to multiple ip addresses

Hi, I need script that will allow me to connect to multiple clients using ssh on Ubuntu terminal... I have a txt file with the ip addresses of clients, i need a script that will connect to everyone one by one and send some commands... The idea is to check some settings on every client... (2 Replies)
Discussion started by: marko07
2 Replies

9. UNIX for Dummies Questions & Answers

[SOLVED] Command line mail taking too long to send; unable to qualify my own domain name

Hello, I'm having a problem with my mail. When I send mail, it takes a long time for the send to complete. In the below, datestamp is just a simple script to put in a no-white-space date/time stamp. $ datestamp ; mail woodnt; datestamp 02-05-10@193844 Subject: test timer Cc: ... (0 Replies)
Discussion started by: Narnie
0 Replies

10. 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' lger@nd.com < /data02/transfer/*_experience_rate_log.txt but this not working. i can send... (2 Replies)
Discussion started by: vishalpatel03
2 Replies
Login or Register to Ask a Question