Mailx Recipient and Name Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mailx Recipient and Name Script
# 1  
Old 09-30-2009
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:

Image


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 Smilie

Last edited by slicker; 09-30-2009 at 12:18 AM..
# 2  
Old 09-30-2009
mailx name script

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
# 3  
Old 09-30-2009
Quote:
Originally Posted by pravin27
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.

Smilie
# 4  
Old 10-01-2009
Hi,

Code:
#!/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

Last edited by pravin27; 10-01-2009 at 09:54 AM..
# 5  
Old 10-06-2009
Hi,

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

Code:
#!/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! Smilie

Cheers
Sumedha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Emails sent from Linux server are rejected by recipient

Hello i have this longterm issue which im unable to solve, i think this is quite simple issue, i hope you may know the cause It is on CentOS Redhat server with qmail installed. # service qmail status # service qmail start Starting Qmail: # ps aux | grep mail qmails 1688 0.0 0.0 ... (1 Reply)
Discussion started by: postcd
1 Replies

2. Shell Programming and Scripting

Mailx recipient from mysql database

Dear All, Can I make Mailx to read recipient address from a mysql database? I already tried emailing with bash script: SUBJECT="TEST" export EMAIL_ADDRESS=`mysql -uroot -pabcde smsd -e "SELECT email FROM recipient"` mysql -uroot -pabcde smsd -e "SELECT ID, SenderName, Body FROM inbox" |... (14 Replies)
Discussion started by: jazzyzha
14 Replies

3. Programming

Mailx recipient from mysql database

Dear All, Can I make Mailx to read recipient address from a mysql database? I already tried emailing with bash script: SUBJECT="TEST" export EMAIL_ADDRESS=`mysql -uroot -pabcde smsd -e "SELECT email FROM recipient"` mysql -uroot -pabcde smsd -e "SELECT ID, SenderName, Body FROM inbox" |... (2 Replies)
Discussion started by: jazzyzha
2 Replies

4. 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

5. 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

6. UNIX for Dummies Questions & Answers

Configure Recipient Restrictions in Postfix

Hi all We need to block our users sending emails to specific email addresses. At the moment, recipient restrictions is not enabled in our Postfix relay server so all messages submitted from our Exchange server are accepted and relayed. See entries in our main.cf file: ### Recipient... (0 Replies)
Discussion started by: wbdevilliers
0 Replies

7. UNIX for Dummies Questions & Answers

mailx recipient restriction

maybe a simple question, but i've looked around and not been able to find anything. is there a restriction on how many recipients can be used in a single mailx command? whether it's a numeric restriction or a size restriction (like 256k for the whole recipient parameter). thanks a lot. (6 Replies)
Discussion started by: chris32680
6 Replies

8. UNIX for Dummies Questions & Answers

sendmail recipient issue

I can send external emails from one of my unix boxes but can no longer send internal emails, i have used mailx -v to see what's going on and it seems there is a problem with the RCPT TO part of the log It seems to add name@nsmail1.mydmn.gov.uk When it should be just name@mydmn.gov.uk The... (1 Reply)
Discussion started by: supadid
1 Replies

9. Shell Programming and Scripting

Creating a multi-recipient email script

Well, I'm fairly new to shell scripting, so please excuse my newbieness :) 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... (2 Replies)
Discussion started by: TheSunTheSea
2 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