Creating a multi-recipient email script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a multi-recipient email script
# 1  
Old 01-31-2004
Creating a multi-recipient email script

Well, I'm fairly new to shell scripting, so please excuse my newbieness Smilie

I was wondering if it was possible to create a shell script that retrieves a list of recipients in a list_file and sends a message out all at once?

An example of a list file would look similar to this:

$ cat data/list_file
user1@host_xyz nickname1
user2@host_abc nickname2
..... ......
userN@host_N nicknameN

As for the message file being emailed, I would LOVE to have it personalized in this fashion for my site:

To {NICKNAME}:

We appreciate your registration to the RSG board. Here are you authorization credentials:

username: {EMAIL}
password: {PASSWORD}

Your RSG account will expire on: {EXPIRATION_DATE}

Cheers,

System Admin

Now, I've only been playing around with shell scripts for a few days, but I know I can use "mkpasswd" to create a password for the user and "date" to calculate the expiration date (which is exactly one year after the email is sent). I'm also assuming that I can use "sed" to substitute the correct fields, correct?

Well, I really don't know how to begin on this. I think it would be great for my site if I can implement something like this. I'd much rather stick to this shell scripting idea since I haven't really touched on it before.

If anyone has some code I can look at or tips to give me, I would greatly appreciate it.
# 2  
Old 01-31-2004
Here's an update. This is what I've written so far and I'm getting a whole bunch of errors:

Code:
#!/bin/sh
#usage mailscript msg_file  list_file  "subject"

MAILTEXT=$1
INFILE=$2
SUBJECT=$3

exec 0<${INFILE}
while read EMAIL NICKNAME
do

PASS=`/usr/linux/bin/mkpasswd`
EXDATE=`/usr/linux/date --date 'next year' +%F`

 sed -e "s/{NICKNAME}/$NICKNAME/g" -e "s/{EMAIL}/$EMAIL/g" -e 
"s/{PASSWORD}/$PASS" -e "s/{EXPIRATION_DATE}/$EXDATE" $MAILTEXT | mailx -s 
"$SUBJECT" $ADD

done

exit

#End of script


Since I've only been playing around with scripts for a few days, I have no idea what I'm doing wrong. It seems right to me, but it's not working. If anyone can help me out I'd greatly appreciate it.
# 3  
Old 02-02-2004
I use ksh, not sh...

I assume that the only two fields in list_file are EMAIL and NICKNAME. Instead of

exec 0<${INFILE}
while read EMAIL NICKNAME
do

you could try using

cat $INFILE |
while read EMAIL NICKNAME
do

Even though it looks like your sed command would work for me (in ksh), it may not work in sh. Did you create that sed command from an example you found somewhere?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Send multi content email using sendemail utility

Hi Guys, I am trying to send email from solaris server using sendemail utility. I want to send multi content email. For example, i want to send email body with html file and a attachment of txt file. I using below code but the html not render correctly in email body. ( echo "To:... (2 Replies)
Discussion started by: tharmendran
2 Replies

2. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

3. Shell Programming and Scripting

sendmail script throwing an error "No recipient addresses found in header"

Hi, I am using following code to send an e-mail with attachment and body. echo "To: user1@mail.com,user2@mail.com" > mail.tmp echo "Cc: user3@mail.com,user4@mail.com" >> mail.tmp echo "From: group@mail.com" >> mail.tmp echo "Subject: my report" >> mail.tmp echo "please see as attached"... (6 Replies)
Discussion started by: vivek_damodaran
6 Replies

4. Shell Programming and Scripting

Send email recipient based on filename

Hi All can someone help please create a bash script. Here's a scenario: 1. I have a directory where it's a destination for scanned documents. e.g. /dest/scan 2. The filename is in the form IDNumber_Category. e.g. 123456_notes.pdf 3. The first part of the script is to rename the... (1 Reply)
Discussion started by: aemestech
1 Replies

5. Shell Programming and Scripting

Mailx Recipient and Name Script

Hi To All, I have a file with email addresses, most of which have names associated with them, it looks like this: http://img230.imageshack.us/img230/8255/94731317.th.jpg I am trying to come up with a script to use mailx (or anything else really) to send an email to... (4 Replies)
Discussion started by: slicker
4 Replies

6. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

7. Programming

Creating email account prgramatically + java ?

Dear Friend, I am working on java application which requires that after successful registration an email account is created (say username@mydomain.com) for user. Is is possible to create e-mail account programatically ? Enviornment - CentOs, Tomcat Web server. CPanel is available, but... (0 Replies)
Discussion started by: reckless_jack
0 Replies

8. UNIX for Dummies Questions & Answers

Email recipient problems with uuencode attachments

Most of my email attachments are fine, but some recipients get the email with the uuencode attachment included as "text" at the end of the body of the message. Has anybody seen this? It seems to happen most with yahoo, msn and other freebie email addresses. Thanks (1 Reply)
Discussion started by: Dave Miller
1 Replies

9. Shell Programming and Scripting

creating email based on an output

Hello folks. I need to create a script that looks at a certain output (list of full paths of files) and gets the owner's name (2nd position in the path, for example: /dirA/jsmith/blah1/more_blah/still_blah... etc) Gets the jsmith and greps the related file for jsmith and send that output to... (1 Reply)
Discussion started by: saswerks
1 Replies

10. UNIX for Dummies Questions & Answers

Unknown recipient when using metasend

Hi, We use metasend to send e-mail from our app. This works fine with most kinds of mail, for example plain text, HTML with images and mail with attachments. But we still have one problem: If the to-address is misspelled, then still everything seems to be fine. We don't get any message back... (4 Replies)
Discussion started by: sjohnsen
4 Replies
Login or Register to Ask a Question