Find the answer to your Linux question:
Results 1 to 3 of 3
I'm very new at this, so pardon me if this question is very newbie-like. I'm doing some testing against SMTP servers, and need to automate it a bit. What I ...
  1. #1
    Just Joined!
    Join Date
    Oct 2006
    Posts
    7

    Telnet SMTP bash script

    I'm very new at this, so pardon me if this question is very newbie-like.

    I'm doing some testing against SMTP servers, and need to automate it a bit. What I want to do, is make a bash script that telnets to an SMTP server and sends the commands and data, then quits. I've tried doing it like this (which is probably way off):

    Code:
    #!/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
    This works, up to the DATA command. 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 sending the data that I don't know. And I haven't been able to find anything usefull about it on the net, so therefore I'm askin here.

    Thanks for all tips and help.

  2. #2
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    You use netcat for this, not telnet.

    Code:
    [xxx@xxx src]$ nc localhost 25 << EOF
    > HELO localhost
    > MAIL FROM: user@whatever.com
    > RCPT TO: user@whatever.com
    > DATA
    > this is a test
    > .
    > QUIT

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Posts
    7
    I will try that. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...