Sending mails to various users without hard coding the email IDS


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sending mails to various users without hard coding the email IDS
# 1  
Old 06-02-2008
Sending mails to various users without hard coding the email IDS

Hi

Can any one help me out ?

I am trying to send an autogenerated mail with an attachment to bulk of users using 'MAILX' and 'UNENCODE' . I have used it as follows

X " ( cat /sastemp/body.txt; uuencode Test.xls.gz Test.xls.gz ) | mailx -s 'Testing' ' abcd@yahoo.com , efgh@gmail.com ' "

But the problem here is, we dont want to hard code the email ids in our program. So can any one let me know how to sort it out with out hard coding the email ids and sending the mail to bunch of people.

Thanks in advance.

Regards.
Manas
# 2  
Old 06-02-2008
Depends on the way you want to feed your script with email adresses.

One possible way is, to use just replace the emails in your script by using the variable
Code:
$@

or
Code:
$*

where for this script it might not make a difference which of both you use. So if you call your script, you can use it for example like
Code:
./mailscript.ksh garry@b.org jupp@bla.com mike@fodder.net

If you want get them from a file, just use a while/read or for/cat construct maybe.
# 3  
Old 06-02-2008
Then how do you propose to know where to send them?
# 4  
Old 06-02-2008
Hammer & Screwdriver

You should use a $@ in your script and pass the emailid as parameters to the script.
# 5  
Old 06-02-2008
Hi all

Thanks for you valuable inputs.

My objective is to keep all the emails IDs in a file or dataset and use a unix command which retrives the email ids from that file/dataset and send it to respective users. Currently 100 users are there and every month some of the users get added to the existing users list. So every time it is difficult to change the code. To avoid this I want to create a file or dataset where we can keep or modify the users on monthly basis. i have tried using 'CAT' but unable to succeed. Can you please give the clear sintax of the same.

Thanks for your time.

Regards,
Manas
# 6  
Old 06-02-2008
I don't know how much parameters (ie. email addresses) your mail client will be able to process

Your list should look like:
Code:
address1
address2
address3
address4
address5
...

Code:
cat addressfile |\
while read ADDRESSES; do
   read ADDRESSES
   (echo "here is the data!" | uuencode datafile datafile) mail -s "mysubject" ${ADDRESSES}
done

In this example mail will be invoked for each single line of input. So you will not have to fear that your mail client has problems with processing too many addresses ie. parameters at once.
# 7  
Old 06-02-2008
Hi

Thanks for your inputs.

The code looks fine but had a small query in my mind regarding the code.

The addressfile you have mentioned should be in which format(.txt???).

Can you please let me know whether the addressfile and ADDRESSES should be with the same name??

Thanks

Manas
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Email IDs added to .mailrc aliases not receiving mails

hi, I added an email id to a list of existing aliases in .mailrc on my unix box, using vi editor. However, the new id has not been receiving any mails from the box. Kindly help as to what needs to be done here. Does the box need to be rebooted for these changes to reflect? Is there any other... (5 Replies)
Discussion started by: qwerty000
5 Replies

2. Solaris

Sending Mails to the Multiple Email Address

Hi All, I am pretty new to the mail service in Sun Solaris 5.10. If anybody help me in writing a script for the multiple recipient with subject and the body would be a helpful. Kindly help... Thanks in advance. :) Warm Regards, Pramod (5 Replies)
Discussion started by: Pramod_009
5 Replies

3. Shell Programming and Scripting

How to send mails based on email ids residing in table?

Hello Gurus, I have one table which consists of two field:- PROG_NAME EMAIL xxxx email1,email2,email3 yyyy email4,email1,email2 I want to to send mails by using mailx command. But how do I get each and every mail ids from table against... (4 Replies)
Discussion started by: pokhraj_d
4 Replies

4. Web Development

Using LWP without hard coding password

Hi, I would like to read content from a https site. I have decided to use LWP module in perl. but it throwed 401 Authorization required error. i dont want to hard code the password in my perl code. Is there any way to achieve the authentication without hardcoding the password. Thanks,... (1 Reply)
Discussion started by: pandeesh
1 Replies

5. HP-UX

Sending email to multiple IDs

Hi, I am trying to send an email to multiple IDs from Unix script. I have given the EmailIds in a file and trying to use the file as input in the script. > cat Email EmailID = "abc@xyz.com cbz@xyz.com" In my script I have . /Email mailx -s "subj" $EmailID This fails with the... (3 Replies)
Discussion started by: sangharsh
3 Replies

6. Programming

char constants vs. hard-coding

This might be a silly question, but I thought I'd ask anyway. If I'm writing in C, isn't it more efficient to, for instance, use constant character variable set to 'A' instead of hard-coding a character 'A'? Since it's only a single character instead of a string, it might not matter much. (10 Replies)
Discussion started by: cleopard
10 Replies

7. Shell Programming and Scripting

Sending an email to group of users

Hi , I want to write a Unix script which can send an automatic email to the group when my job is completed.I'm trying the following Mail -s "test" <groupname> << EOD >Completed >EOD With this i'm not able to send an email to group..Any ideas? Thanks in Advance (1 Reply)
Discussion started by: BhawanaAggarwal
1 Replies

8. Shell Programming and Scripting

I wanted to update a script, more dynamic (just say no to hard coding)...

currently it has the following: bdumpN=`ll /home/apps/oracle/admin/DBprod/bdump/DBprod_j* | grep "$Cdate" | wc -l` If I pass the DBname, I would not have to hardcode it in the script... I can capture the database name by adding the following: DBname=$1 The problem is, I have been unable... (2 Replies)
Discussion started by: mr_manny
2 Replies

9. UNIX for Dummies Questions & Answers

Sending Mass mails

Hi Forum, I am extremely new to unix.Can somebody please help me out with the following: I am supposed to write a script that will ftp a file which is a .csv and conatins the following: Mail-id Path of file abc@xyz.com D:\xyz\abc.htm ash@sde.com ... (1 Reply)
Discussion started by: iyerdeepa82
1 Replies
Login or Register to Ask a Question