Register
It is currently Tue Oct 21, 2014 9:12 pm

smtpd in bash with a bug(run via inetd ot tcpsvd)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 PostPosted: Tue Mar 29, 2011 11:03 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Wrote this up the other day "for fun" to use with a micro linux distribution based on a monolithic busybox, a monolithic bash, and a kernel and its associated modules that I'm building.(the /lib directory is empty except for the modules directory)
It works and receives email from another machine on my home network using the seamonkey mail client.
Got the idea from a guy that wrote a "fortune" pop3 server in bash.

The bug is in a
"MESS `cat `" call to grab the entire mail, headers and all as a single block of text and plop it into a variable called $MESS for further mutilating later in the script.
It sends the mail(or actually receives) but seamonkey mail or the script times out waiting before it dumps the mail into a file in the user directory.
If anyone can come up with a bug fix I'd be very grateful, as I'm just a rank newbie who cobbled this thing together while "reading" the advanced BASH scripting guide, a few other BASH tutorials, and info from all over the place.

Code:
#!/bin/sh

echo "220 smtpeed scryptic SMTPD"
read RETADDR
echo "250 Hello $RETADDR Glad to meat you"
read FROM
echo "250 OK"
read TO
echo "250 OK"
read MSS  #just a kludge to get past the DATA command
echo "354"
MESS=`cat `
echo "$MESS" > /tmp/mess1.txt
echo "250"                                   
MESSAGE=` cat /tmp/mess1.txt | sed 's/&/'\\\\\\\n'/g' `
USR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $3}' `
FRM=` echo $FROM | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $3}' `
NOW=`date +"%d%I%M%S" | sed "s/ /M/g" `
echo -e "$MESSAGE" >> /home/users/$USR/$FRM$NOW.txt
echo "221 BYE"


Top
 Profile  
 PostPosted: Wed Mar 30, 2011 3:33 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
While most of the time SMTP clients will send the order HELO, MAIL FROM, RCPT TO, DATA. it is not a mandatory order.
I could as well switch the MAIL FROM and RCPT TO commands. This script will mess up some stuff there.
Also the username and/or (home)dir for the recipient is not checked.

For your question: I would use something like this:
Code:
tmp="/tmp/$(basename $0).$$.tmp"
while read line; do
  [ "$line" == "." ] && break
  echo "$line"
done > "$tmp"
MESS=$(cat "$tmp")

Don't forget to clean up/remove the $tmp file before the script ends.


Top
 Profile  
 PostPosted: Wed Mar 30, 2011 3:59 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
My script "here" does have username and passwordfeatures.

Anyways I can redo the script in a while do loop and grab and read replies from the client and execute those via"case"


Top
 Profile  
 PostPosted: Sun Apr 03, 2011 7:25 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Well I've been looking at the "telnetting into smtp" stuff on the net.
I saw reference to servers giving messages saying something about "must give mail from before rcpt to".

Think I'll look into incorporating something like into this script.


Top
 Profile  
 PostPosted: Mon Apr 04, 2011 2:01 am   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Patsie,

I got your little patch working.
er uh, it took yet another dos2unix call because the last line in an email body isn't a "."
it's a ".\r\n", Bash doesn't like the "\r", and I don't know enough yet to figure out some more elegant way to work around it
I used my /tmp/mess1.txt because it was easier for me to work with than your moving target "tmp="/tmp/$(basename $0).$$.tmp""

It's still "lumpy and ugly" code, but at least it doesn't hang the client till it times out, which the client then reports as a failure to send the mail.

Code:
##########newcode########
tmp="/tmp/mess1.txt"
while read line; do
lin=`echo $line | dos2unix `
    [ "$lin" == "." ] && break
  echo "$lin"
done > "$tmp"
MESS=$(cat "$tmp")
########################


Top
 Profile  
 PostPosted: Mon Apr 04, 2011 2:48 am   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Well attachments "used" to work, now when I attach anything I get a blank message body*chuckles*


Top
 Profile  
 PostPosted: Tue Apr 05, 2011 1:00 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
I fiddled a little more with the smtpd script last night.
Got rid of the "dos2unix" call after digging around to learn how to represent a carriage return.
Came up with this

Code:
tmp="/tmp/mess1.txt"
while read line; do
    [ "$line" == $'.\r' ] && break
  echo "$line"
done > "$tmp"
MESS=$(cat "$tmp")


So the smtpd doesn't hang till whatever timesout and that's a good thing
The attachments are still broken, and trying to send one results in a blank mail.
It's funny, because the mail attachment and all, makes it intact into the mail "spool" directory and can be read there using a text editor, and if one telnets into the pop server it shows up during a RETR call, and the "mail" shows up in the client software as having an attachment so I'm wondering whether the pop3 script is doing something wrong, as this has happened early in the very beginning of this project of mine.


Top
 Profile  
 PostPosted: Tue Apr 05, 2011 11:26 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Well, the timing/timeout bug is gone(thanks to Patsies example code and advice) and I got attachments working correctly.
Just had to wrap the darn mail body itself in more sed duct tape to add some spaces to the boundary, name, and filename sections of the mail headers.*laughs*

Now all I have to add in is some tests to foil potential intruders at the gates and the whole thing "should" be good to go.


Top
 Profile  
 PostPosted: Wed Apr 06, 2011 11:34 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Very nice! I'm curious to see the next evolutionary step in this SMTP service.


Top
 Profile  
 PostPosted: Wed Apr 06, 2011 3:47 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Well, I'm going to have to fiddle with netcat a bit to see exactly what the various mail client software "wants" for responses and work that out in order to get this thing to be more than just a toy.*grins*


Top
 Profile  
 PostPosted: Wed Apr 06, 2011 10:28 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
OOPS! the RFC's are pretty strict when it comes plain text authorization.
Well guess it's back to the drawing board for a day or two while I figure out out to comply to the RFC's *grins*


Top
 Profile  
 PostPosted: Thu Apr 07, 2011 6:35 am   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Well here's the latest incarnation of the smtpd.
I added an AUTH LOGIN "fork" using the RFC standard base64 encoding, and a lame attempt at relaying for authenticated users while non- authenticated users/inbound mail from other MTA's can still get in to deliver mail to "$ME" without the option to relay.
And yeah I still didn't fix some of the issues from the first incarnation, but geez.........I can only do so much in one night.
Time for me to crash& burn for a few hours*grins*

Code:
#!/bin/bash

ME="mymail.me"

function relay ()
{
    (
    sleep 3
   echo "$FRM"
   sleep2
    echo "$FROM"
    sleep 1
    echo "$TO"
    sleep 1
   echo "DATA"
   echo -e "$MESSAGE"
   echo "."
   sleep 1
   echo "QUIT"
   ) | telnet smtp.$SVR 25 #fixed?
   echo "" > /tmp/mess1.txt
   exit;
}

function esmtpd ()
{
echo "334 VXNlcm5hbWU6"
read nam
num=`echo "$nam" | dos2unix `
nom=`cat /home/users/users | sed -n "/$num/p" | awk '{print $1}' `
if [ "$num" != "$nom" ]; then
echo " 451 bad username"
exit;
else
      echo "334 UGFzc3dvcmQ6"
      read passw
     pissw=`echo "$passw" | dos2unix `
     possw=`cat /home/users/users | sed -n "/$num/p" | awk '{print $2}' `
             if [ "$pissw" != "$possw" ]; then
           echo "501 bad password"
           exit;
           else
           echo "got the password" > /root/smtp.log
           echo "235 2.7.0 Authentification successful"
read FROM
echo "250 sender OK"          
read TO
echo "250 OK"
read MSS                       #kludge to get past DATA
echo "354"
##################
tmp="/tmp/mess1.txt"
while read line; do
    [ "$line" == $'.\r' ] && break
  echo "$line"
done > "$tmp"
MESS=$(cat "$tmp")
########################
echo "250 OK: mail queued closing connection"                                   
MESSAGE=` cat /tmp/mess1.txt | sed 's/boundary/ boundary/g' | sed 's/name/ name/g' | sed 's/filename/ filename/g'  `
USR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $3}' `
FRM=` echo $FROM | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $3}' `
NOW=`date +"%d%I%M%S" | sed "s/ /M/g" `
SVR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $4}' `
if [ "$SVR" != "$ME" ]; then
relay
else
echo -e "$MESSAGE" >> /home/users/$USR/$FRM$NOW.txt
echo "" > /tmp/mess1.txt  #covers yer tracks
echo "221 BYE"
fi
fi
fi
}
          
echo "220 smtpeeder scryptic SMTPD"
read RETADDR
echo "250 AUTH LOGIN"
read FROM
FRIM=`echo "$FROM" | awk '{print $1}' `
if [ "$FRIM" = "AUTH" ]; then
esmtpd
else
echo "250 OK"
read TO
echo "250 OK"
read MSS                       #kludge to get past DATA
echo "354"
##################
tmp="/tmp/mess1.txt"
while read line; do
    [ "$line" == $'.\r' ] && break
  echo "$line"
done > "$tmp"
MESS=$(cat "$tmp")
########################
echo "250 OK: mail queued closing connection"                                   
MESSAGE=` cat /tmp/mess1.txt | sed 's/boundary/ boundary/g' | sed 's/name/ name/g' | sed 's/filename/ filename/g'  `
USR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $3}' `
FRM=` echo $FROM | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $3}' `
NOW=`date +"%d%I%M%S" | sed "s/ /M/g" `
echo -e "$MESSAGE" >> /home/users/$USR/$FRM$NOW.txt
echo "" > /tmp/mess1.txt  #covers yer tracks
echo "221 BYE"

fi


Last edited by ZooT_aLLures on Sun Apr 10, 2011 12:50 pm, edited 2 times in total.

Top
 Profile  
 PostPosted: Thu Apr 07, 2011 4:14 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
DamnI forgot to define $SERVER in that script.
Probably because I couldn't test the relaying without have a "real" domainname mx record and all that other happy crap to test it "from".

Oh well , I'll fix that.

(update)
A funny thing happened on the way to multiuserland.
Seems that the pipe to sed in the username and password was simply printing the /home/users/users file and piping it to awk.
The username is not "every" first field as awk was printing it nor the password every second field.
In addition, neither the username nor the password is what the mail client sends, but instead what's left after dos2unix strips the carriage return off.

Fixed the code above and now multiusers works correctly.


Top
 Profile  
 PostPosted: Wed Apr 13, 2011 5:23 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Here's the latest smtpd.
As with the pop3d changes have been made for client compatability.

Still having problems "getting mail" using sylpheed, but sylpheed sends now, as does the generic "sendmail" applet in busybox.
Anyways here's the code

Code:
#!/bin/bash

ME="mymail.me"
function relay ()
{
    (
    sleep 3
   echo "$FRM"
   sleep2
    echo "$FROM"
    sleep 1
    echo "$TO"
    sleep 1
   echo "DATA"
   echo -e "$MESSAGE"
   echo "."
   sleep 1
   echo "QUIT"
   ) | telnet smtp."$SVR" 25
   echo "" > /tmp/mess1.txt
   exit;
}
function esmtpd ()
{
echo "334 VXNlcm5hbWU6"
read nam
num=`echo "$nam" | dos2unix | base64 -d `
nom=` cat /home/users/users | sed -n "/$num/p" | awk '{print $1}' | base64 -d `
if [ "$num" != "$nom" ]; then
exit;
else
      echo "334 UGFzc3dvcmQ6"
      read passw
     pissw=`echo "$passw" | dos2unix | base64 -d `
     possw=`cat /home/users/users | sed -n "/$num/p" | awk '{print $2}' | base64 -d `
             if [ "$pissw" != "$possw" ]; then
           echo "501 Bad  Password"
           exit;
           else
           echo "235 2.7.0 Authentification successful"
read FROM
echo "250 sender OK"          
read TO
echo "250 OK"
read MSS                       #kludge to get past DATA
echo "354"
tmp="/tmp/mess1.txt"
while read line; do
    [ "$line" == $'.\r' -o "$line" = "." ] && break
  echo "$line"
done > "$tmp"
MESS=$(cat "$tmp")
echo "250 OK: mail queued closing connection"                                   
MESSAGE=` cat /tmp/mess1.txt | sed 's/boundary/ boundary/g' | sed 's/name/ name/g' | sed 's/filename/ filename/g'  `
USR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $3}' `
FRM=` echo $FROM | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $3}' `
NOW=`date +"%d%I%M%S" | sed "s/ /M/g" `
SVR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $4}' `
if [ "$SVR" != "$ME" ]; then
relay
else
echo -e "$MESSAGE" >> /home/users/$USR/$FRM$NOW.txt
echo "" > /tmp/mess1.txt  #covers yer tracks
echo "221 BYE"
fi
fi
fi
}

function jump()
{
echo "250 AUTH LOGIN"
read FRUM
FROM=`echo "$FRUM" | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $0}' `
FRIM=`echo "$FROM" | awk '{print $1}' `
if [ "$FRIM" = "AUTH" ]; then
esmtpd
else
echo "250  sender OK"
read TO
echo "250 recipient OK"
read MSS                       #kludge to get past DATA
echo "354 End message with a ."
tmp="/tmp/mess1.txt"
while read line; do
    [ "$line" == $'.\r' -o "$line" = "." ] && break
  echo "$line"
done > "$tmp"
MESS=$(cat "$tmp")
echo "250 OK: mail queued closing connection"   
echo "sent meesage queued message" >> /root/smtp.log                                 
MESSAGE=` cat /tmp/mess1.txt | sed 's/boundary/ boundary/g' | sed 's/name/ name/g' | sed 's/filename/ filename/g'  `
USR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $3}' `
FRM=` echo $FROM | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $3}' `
NOW=`date +"%d%I%M%S" | sed "s/ /M/g" `
echo -e "$MESSAGE" >> /home/users/$USR/$FRM$NOW.txt
echo "" > /tmp/mess1.txt  #covers yer tracks
echo "221 BYE"
fi
}

function goin()
{
   while read lump; do
   COMMAND="${lump:0:4}"
   case "$COMMAND" in
   NOOP)
            echo "250 OK"
   lomp=`echo "$lump" | awk '{print $1}' `
   ;;
   EHLO)
   jump
   ;;
   HELO)
   jump
   ;;
   esac
   done
}   

echo "220 mymail.me scryptic SMTP"
goin
exit;


And yeah, there's at least one uncalled variable in there.
They're residue from the hundred and one "signposts" in my working copy of the code that echo virtually ever step, both input and output to my debug file, so I can tell exactly where the script pukes while I'm hacking at the code.*grins*


Top
 Profile  
 PostPosted: Fri Apr 15, 2011 5:25 am   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Code:
tmp="/tmp/$(basename $0).$$.tmp"


Well Patsie, I couldn't figure out why you'd introduce a moving target temp file.
Now I'm getting to the multi-user stage, and it seems I figured it out*L*


Top
 Profile  
 PostPosted: Sun Apr 17, 2011 1:03 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Glad to have been of service :)


Top
 Profile  
 PostPosted: Tue Apr 19, 2011 2:10 am   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
It's time for me to look into lockfiles and maybe a temp spool for spooling while one or more lockfiles are in place, and maybe a third script to proccess that temp spool from time to time.


Top
 Profile  
 PostPosted: Tue Apr 19, 2011 3:10 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Whenever you have something ready, I'll be happy to give some feedback/critique/tips for improvement.


Top
 Profile  
 PostPosted: Tue Apr 19, 2011 5:47 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
I'm up to that.

After all critical appraisal is the best form of assistance, and hints force me to think rather having someone do my thinking for me*grins*


Top
 Profile  
 PostPosted: Sun Apr 24, 2011 4:33 am   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Here's the latest smtpd
It incorporates mail directory locking based whether the current PID written to the mail directory lockfile is valid or not.
It also incorporates a mail temp spool and proccesses the temp spool during the next unlocked "run" of the smtpd itself.
A valid PID in the lockfile causes the smtpd to write to the temp mail spool
I added the locking code to a new function called "riteit"

Code:
#!/bin/bash

SPOOL="/home/users"
tmp="/tmp/mess.$$.tmp"
ME="mymail.me"

function riteit ()
{
ufl=`cat $SPOOL/$USR.lock `
tp=` ps p "$ufl" | sed '/PID/d' | awk '{print $1}' `
if [ -z "$tp" ];
then
echo "$$" > "$SPOOL/$USR".lock
echo -e "$MESSAGE" >> "$SPOOL/$USR/$FRM$NOW".txt
cp "$SPOOL/temp/$USR/"* "$SPOOL/$USR"
rm "$SPOOL/temp/$USR/"*
rm "$tmp"
echo "221 BYE"
exit;
else
echo -e "$MESSAGE" >> "$SPOOL"/temp/"$USR/$FRM$NOW".txt
rm "$tmp"
echo "221 BYE"
exit;
fi
}
function relay ()
{
    (
    sleep 3
   echo "$FRM"
   sleep2
    echo "$FROM"
    sleep 1
    echo "$TO"
    sleep 1
   echo "DATA"
   echo -e "$MESSAGE"
   echo "."
   sleep 1
   echo "QUIT"
   ) | telnet smtp."$SVR" 25
   rm "$tmp"
   exit;
}

function esmtpd ()
{
echo "334 VXNlcm5hbWU6"
read nam
num=`echo "$nam" | dos2unix | base64 -d `
nom=` cat /home/users/users | sed -n "/$num/p" | awk '{print $1}' | base64 -d `
if [ "$num" != "$nom" ]; then
echo "Bad username BYE!"
exit;
else
      echo "334 UGFzc3dvcmQ6"
      read passw
     pissw=`echo "$passw" | dos2unix | base64 -d `
     possw=`cat /home/users/users | sed -n "/$num/p" | awk '{print $2}' | base64 -d `
             if [ "$pissw" != "$possw" ]; then
           echo "501 Bad  Password"
           exit;
           else
           echo "235 2.7.0 Authentification successful"
read FROM
echo "250 sender OK"          
read TO
echo "250 OK"
read MSS                       #kludge to get past DATA
echo "354"
#tmp="/tmp/mess1.txt"
while read line; do
    [ "$line" == $'.\r' -o "$line" = "." ] && break
  echo "$line"
done > "$tmp"
MESS=$(cat "$tmp")
echo "250 OK: mail queued closing connection"                                   
MESSAGE=` cat "$tmp" | sed 's/boundary/ boundary/g' | sed 's/name/ name/g' | sed 's/filename/ filename/g'  `
USR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $3}' `
FRM=` echo $FROM | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $3}' `
NOW=`date +"%d%I%M%S" | sed "s/ /M/g" `
SVR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $4}' `
if [ "$SVR" != "$ME" ]; then
relay
else
riteit
fi
fi
fi
}

function jump()
{
echo "250 AUTH LOGIN"
read FRUM
FROM=`echo "$FRUM" | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $0}' `
FRIM=`echo "$FROM" | awk '{print $1}' `
if [ "$FRIM" = "AUTH" ]; then
esmtpd
else
echo "250  sender OK"
read TO
whoto=`echo "$TO" | sed 's/@/ /g' | awk '{print $4}' `
if [ "$whoto" != "$ME" ];
then
echo "RCPT To: not local"
echo "relaying not allowed without authentification"
exit;
else
echo "250 recipient OK"
read MSS                       #kludge to get past DATA
echo "354 End message with a ."
#tmp="/tmp/mess1.txt"
while read line; do
    [ "$line" == $'.\r' -o "$line" = "." ] && break
  echo "$line"
done > "$tmp"
MESS=$(cat "$tmp")
echo "250 OK: mail queued closing connection"   
echo "sent message queued message" >> /root/smtp.log                                 
MESSAGE=` cat "$tmp" | sed 's/boundary/ boundary/g' | sed 's/name/ name/g' | sed 's/filename/ filename/g'  `
USR=` echo $TO | sed 's/</ /g' | sed 's/>/ /g' | sed 's/@/ /g' | awk '{print $3}' `
FRM=` echo $FROM | sed 's/</ /g' | sed 's/>/ /g' | awk '{print $3}' `
NOW=`date +"%d%I%M%S" | sed "s/ /M/g" `
riteit
fi
fi
}

function goin()
{
   while read lump; do
   COMMAND="${lump:0:4}"
   case "$COMMAND" in
   NOOP)
            echo "250 OK"
   lomp=`echo "$lump" | awk '{print $1}' `
   ;;
   EHLO)
   jump
   ;;
   HELO)
   jump
   ;;
   esac
   done
}   

echo "220 mymail.me scryptic SMTP"
goin
exit;


Top
 Profile  
 PostPosted: Sun Apr 24, 2011 6:42 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Figured I'd better mention that I had to download the latest, greatest procps package and compile "minimal.c" as a static binary built against uCLibC to get the latest working under my little linux systems busybox/bash environment because the busybox "ps" applet doesn't recognize the "p" flag.

So the entire system nows weighs in at a bloated 7 megabytes *grumbles*


Top
 Profile  
 PostPosted: Thu Apr 28, 2011 11:22 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
So er uh.............I've hit yet another brick wall.

Outlook express can send mail to to the smtpd but can't receive mail from the pop3d, and pegasus mailer can receive mail from the pop3d but can't send mail smtpd.

When I use netcat as a "listener" to emulate both scripts, every thing "looks" right.

In particular outlook express hangs when receiving, like it doesn't know that the message transfer is complete and after adding "signposts" throughout the script that sends "echoed output of variables as flags" to my logfile, the transfer is completed, but apparently outlook express is waiting for something more.........like maybe some special "EOF" kinda' thing in addition to the line containing only a period.


Top
 Profile  
 PostPosted: Fri Apr 29, 2011 10:45 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
The official end of line termination for both POP3 and smtp services is a carriage return plus a newline. If you are using this as a script in Unix your echo's are only returning newline's. Especially something Microsoft like Outlook may trip over this and wait for a propper EOL.


Top
 Profile  
 PostPosted: Fri Apr 29, 2011 7:45 pm   

Joined: Tue Mar 29, 2011 10:14 pm
Posts: 32
Well after ten gazillion messed up tries and a cubic meter of bits in the bucket, I got it working*grins*

Had to create a file in /home/users named "per.txt" and created it using geany that'll do either dos or unix line terminators.
Then I just butchered the script to get it to "echo-a-cat-of-that-file" to get it to send the needed CRLF.CRLF

And yeah............It might be no biggie for some salty old scripter.........but I'm fairly pleased with getting it working*grins*


Top
 Profile  
 PostPosted: Sat Apr 30, 2011 1:36 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
There are perhaps some easier methods of generating Microsoft newlines.
Code:
echo -e "test\r"
printf "test\r\n"

Or you can make a function called 'send' like this:
Code:
function send() { echo -e "$@\r"; }
send "hello"


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP