Visit Our UNIX and Linux User Community


Multiple emails via telnet in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple emails via telnet in a script
# 1  
Old 10-13-2010
Multiple emails via telnet in a script

Hi everyone,
I'm writing a script that connect to telnet and write some email taking the RCPT from a file. My problem is the fact I'm not able to put all the addresses I have in the file as subject for the "RCPT TO:"Smilie...

Can anyone please help me?

Thanks

ps: I wrote this right now
(
ADDRESSES=$(cat "/home/addresses")
sleep 1
echo "helo"
sleep 1
echo "mail from:<abc@foo.com>"
sleep 1
echo "rcpt to:$ADDRESSES"
sleep 10
echo "data"
sleep 1
echo "subject:Test message"
sleep 1
echo "from: <abc@foo.com>"
sleep 1
echo "to: $ADDRESSES"
sleep 1
echo " "
sleep 1
echo "Hello."
sleep 1
echo "This is a test message."
sleep 1
echo "Bye."
sleep 1
echo "."
sleep 1
echo "QUIT"
) | telnet xyz.xyz.xyz.zyx
# 2  
Old 10-13-2010
RFC821 - Simple Mail Transfer Protocol

The second step in the procedure is the RCPT command.

RCPT <SP> TO:<forward-path> <CRLF>

This command gives a forward-path identifying one recipient.
If accepted, the receiver-SMTP returns a 250 OK reply, and
stores the forward-path. If the recipient is unknown the
receiver-SMTP returns a 550 Failure reply. This second step of
the procedure can be repeated any number of times.

---------- Post updated at 01:22 PM ---------- Previous update was at 01:19 PM ----------

Extended SMTP - Wikipedia, the free encyclopedia

We google for you! Smilie
# 3  
Old 10-13-2010
so i have better try few times the RCPT as you are suggesting me?
i will tell you if that works...
thanks for googling!Smilie
# 4  
Old 10-13-2010
One per:
Code:
For a in $ADDRESSES
do
  echo "rcpt to:$a" 
  sleep 10 
done

This goes faster if:
  • you use 'expect'/'autoexpect', but it is a bit of a project to use it dynamically if you are not a tk/tcl guru yet, or
  • do your own 'expect': send the telnet output to a flat file and grep for responses in it every second or even less ( I wrote a 'nap' command in trivial C to sleep in milliseconds using poll(0,0,#) ). Of course, for n recipients, you need n+m 'grep -c' responses.

Here is one I wrote when the local mailx did not deliver:

Code:
$ cat mysrc/mailx4            
#!/usr/bin/ksh

waitpat_e(){

        export zt=0

        if [ "$2" = "" ]
        then
                export zc=2
        else
                export zc=$2
        fi

        while (( $(tail -$zc </tmp/dpmail.$$|egrep -c "$1") < 1 ))
        do
                if (( $(fgrep -c 'Connection closed by foreign host.' </tmp/dpmail.$$) > 0 ))
                then
                        exit
                fi

                zt=$(( $zt + 50 ))

                if (( $zt > 10000 ))
                then
                        return 1
                fi

                napx 50

                if [ ! -f /tmp/dpmail.$$ ]
                then
                        return 2
                fi
        done

        return 0
}

waitpat(){

        export zt=0

        if [ "$2" = "" ]
        then
                export zc=1
        else
                export zc=$2
        fi

        while (( $(egrep -c "$1" </tmp/dpmail.$$) < $zc ))
        do
                if (( $(fgrep -c 'Connection closed by foreign host.' </tmp/dpmail.$$) > 0 ))
                then
                        exit
                fi

                zt=$(( $zt + 50 ))

                if (( $zt > 10000 ))
                then
                        return 1
                fi

                napx 50

                if [ ! -f /tmp/dpmail.$$ ]
                then
                        return 2
                fi
        done

        return 0
}

cd

. ./.profile

while [ $# != 0 ]
do
if [ "$1" = "-s" ]
then
  export zsub="$2"
  shift
  shift
  continue
fi
if [ "$1" = "-r" ]
then
  export zsndr="$2"
  shift
  shift
  continue
fi
zrec="$zrec $1"
shift
done

if [ "$zsub" = "" ]
then
  export zsub="From idxx(real_idxx)@hostxxx, no subject"
fi

if [ "$zrec" = "" ]
then
  zrec="David.Pickett@xxx.com"
fi

if [ "$zsndr" = "" ]
then
  export zsndr="David.Pickett@xxx.com"
fi

>/tmp/dpmail.$$

(
waitpat '^220 '
echo "HELO"
waitpat '^250 '
echo "Mail From: $zsndr"
waitpat '^250 ' 2
export zct=3
for r in $zrec
do
 echo "Rcpt To: $r"
 waitpat '^250 ' $zct
 zct=$(( $zct + 1 ))
 zrecs="$zrecs ; $r"
done
"cho "Data
waitpat '^354 '
echo "From: $zsndr
To:${zrecs#*;}
Subject: $zsub
"
*\)$/. \1/'\(
echo "
."
waitpat_e '^250 '
echo "quit"
)|tcpipe -8E mail_host_ip_or_name 25 >/tmp/dpmail.$$ 2>&1

mv -f /tmp/dpmail.$$ /tmp/mailx4_last

$


Last edited by DGPickett; 10-14-2010 at 12:48 PM..
# 5  
Old 10-14-2010
Unfortunately I tried using the "for" as you suggested me but maybe im not able to let this work, because I have seen that in the $ADDRESSES variable there's nothing!

My main problem then, is to do a good assignement every time I am inside the "for loop" giving to $a variable the right value every time.

Thanks for helping me.
# 6  
Old 10-14-2010
I enhanced my reply, above:^
This User Gave Thanks to DGPickett For This Post:
# 7  
Old 10-14-2010
I solved my problem. I am now able to send more emails.

The only problem I have right now is to give it right email addresses (sometimes it said the email address doesnt exist) Smilie

Thanks for helping me!

Bye

Previous Thread | Next Thread
Test Your Knowledge in Computers #994
Difficulty: Medium
A hypervisor or virtual machine monitor (VMM) is a computer software, firmware or hardware that creates and runs virtual machines.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending files to multiple emails

Hi All, I want to send each file to each email id as below. Instead of writing saparate 10 mail commands can we do it in a simple step. file1.csv to raghu.s@hps.com file2.csv to kiran.m@hps.com file3.csv to kenni.d@hps.com file4.csv to rani.d@hps.com file5.csv to sandya.s@hps.com... (2 Replies)
Discussion started by: ROCK_PLSQL
2 Replies

2. Shell Programming and Scripting

Need shell script to Telnet multiple node , Ping some IP and print output

Hi Team, Need shell script to Telnet multiple node , Ping some IP and print output like pass or fail. Need this script to check reachability of multiple nodes at same time. Help me. I use this but not working... Eg. in this script i need to telnet... (4 Replies)
Discussion started by: Ganesh Mankar
4 Replies

3. Shell Programming and Scripting

Avoid multiple emails being sent - Counter, Loop?

Hello, I have currently coded a bash script below in which it does the following: # Archives compressed file from another location. Basically it moves *.gz files to another location. The script also sends an email whenever a new compressed file is placed. This is the issue that i... (5 Replies)
Discussion started by: Wizard_1979
5 Replies

4. Red Hat

Postfix: emails addressed to multiple smart hosts

Hi, I am in process of setting up a SMTP server on RHEL 6 using Postfix. I am stuck at one point so any help would be appreciated. I have configured my xsender to use this new SMTP server as its mail server. If I send any emails addressed TO example.com the SMTP server should use the... (0 Replies)
Discussion started by: max29583
0 Replies

5. UNIX for Dummies Questions & Answers

Export emails into spreadsheet (script)

I 'd like to export emails from my mail client(mac) inbox into an Excel spreadsheet. I need the Subject, From fields, Return-Path and the Message-ID. Does anyone know how I can do this? Thanks, Newbie :) (1 Reply)
Discussion started by: Cris
1 Replies

6. Shell Programming and Scripting

PHP Mail Script Takes Hours to Send emails

guys, i have a php script that i wrote that takes hours to send emails to recipients. i can't post the content of this script in here because the script contains some very important confidential information. so my question is, why is it that when the php script runs, it runs successfully, but... (3 Replies)
Discussion started by: SkySmart
3 Replies

7. Shell Programming and Scripting

mailx script to do multiple emails

I am looking for a script that I can use with mailx to do the following: 1. Grab usernames from a flat file (one at a time) 2. Attach a file to the email and mail out. Thanks. Cubefeed (3 Replies)
Discussion started by: CubeFeed
3 Replies

8. Programming

Sending emails in C program for multiple machines on Linux/OSX

Hey guys, i am creating a tool that'll run a couple network test, generate a report then email the report. Now i a bit stuck with the email sending part... I tried at first a script which worked on some machines but then it'll work fine on some machine and act up on others... I can't really rely... (2 Replies)
Discussion started by: Jess83
2 Replies

9. Shell Programming and Scripting

uuencode mailx - send multiple emails

The following is an extract from one of my Shell Scripts which uses uuencode and mailx to send an email with multiple attachements: uuencode $LOG_REPORT $(basename $LOG_REPORT) uuencode $HTML_FILE $(basename $HTML_FILE ) ) | if then mailx -b "$COPY_TO" -s "$SUBJECT" -r "$MAIL_FROM"... (2 Replies)
Discussion started by: suthera
2 Replies

Featured Tech Videos