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:

I am trying to come up with a script to use mailx (or anything else really) to send an email to each person.

So the first column of the file is grabbed to look like: "Hey Mr A how are you?" - those without names would then look like "Hey how are you?"

Perhaps the name could also be inserted into the message body too.

I tried the mimetool script, did not work for me.

Help appreciated :confused:

Hi ,
Here u go..

test_emal.txt file contains ur name and mail details.

#!/bin/sh
while read line
do
name=`echo $line | awk '{print($1)}'`
email=`echo $line | awk '{print ($2)}'`
if [ -z "$email" ]
then
echo " Hey how are u ? email id - $name"
else
echo " Hey Mr $name how r u ? email id - $email"
fi
name=''
email=''
done < test_emal.txt

---------- Post updated at 07:47 AM ---------- Previous update was at 07:44 AM ----------

Hi ,
Here u go..

test_emal.txt file contains ur name and mail details.

#!/bin/sh
while read line
do
name=`echo $line | awk '{print($1)}'`
email=`echo $line | awk '{print ($2)}'`
if [ -z "$email" ]
then
echo " Hey how are u ? email id - $name"
else
echo " Hey Mr $name how r u ? email id - $email"
fi
name=''
email=''
done < test_emal.txt

Thanks for the response.

Sometimes though the name is 1, 2 or 3 fields, a name could be:

George
or
Mr Read
or
Mr George Read

So I would need to change the IFS to tab or multiple space characters perhaps?

---------- Post updated at 09:42 AM ---------- Previous update was at 08:18 AM ----------

I tried:

name=`echo $line | awk 'BEGIN { FS = "\t" } ; {print($1)}'`

and

name=`echo $line | awk -F"\t" '{print($1)}'`

These work on the command line but not in the script.

:frowning:

Hi,

#!/bin/sh

tr '\011' '#' < test_emal.txt | while read line
do

        name=`echo $line | awk -F'#' '{print($1)}'`
        email=`echo $line | awk -F'#'  '{print ($2)}'`
        [ -z "$name" ] && echo " Hey how are u ? email id - $email" || echo " Hey Mr $name how r u ?  email id  - $email"
        name=''
        email=''

done

Thanks
Pravin

Hi,

The following code snippet is a very simple way of sending mails as plain text or attachments:

#!/bin/ksh
subjectline="--Subject of the mail--"
echo "--Body of the mail--" >> MailingList.txt
echo Sending email ....
cat MailingList.txt |mailx -s "$Subject" -r sender@gmail.com recepient@gmail.com

This will send the body as plain text in the e-mail. In case you wish to send an attachment just replace the last line with 'uuencode' command:
uuencode MailingList.txt MailingList.txt |mailx -s "$Subject" -r sender@gmail.com recepient@gmail.com

This surely should help! :slight_smile:

Cheers
Sumedha