Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Telnet SMTP bash script

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
frankh
Posts: 104
Joined: 2007-06-28 14:08

Telnet SMTP bash script

#1 Post by frankh »

I'm doing some testing against SMTP servers, and I'm wondering how I can create a bash script which telnets to an smtp server and sends the appropriate commands to create a mail. Possibly I can give aguments like recepient, sender etc., but to begin with it can be completely static.

I tried creating a shellscript like this:

Code: Select all

#!/bin/bash
   (
        sleep 1
        echo "ehlo x"
        sleep 1
        echo "mail from:frommail"
        sleep 1
        echo "rcpt to:tomail"
        sleep 1
        echo "data"
        sleep 1
        echo "subject:Test message"
        sleep 1
        echo "from:frommail
        sleep 1
        echo "to:tomail"
        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 172.17.7.140 25
I have no doubt that it's horribly wrong, but it's from a script I found somewhere on the net, so I thought I'd try it out. What happens is that the lines after DATA isn't getting sent, and the connection ends with "cannot accept the message without body". So there's obviously some way of scripting the commands that I don't know. And I haven't been able to find anything usefull about it on the net, so tehrefore I'm askin here.

Thanks for all hints and answers.

User avatar
kladizkov
Posts: 35
Joined: 2007-07-21 04:39

#2 Post by kladizkov »

HI,

Try writing an expect script instead of bash script...

Post Reply