0

I want to create a sh file to send e-mail by telnet. Something like this:

read -p "from: " from
read -p "from (friendly name): " fromf
read -p "dest: " dest
read -p "dest (friendly name): " destf
read -p "subjct: " subjct
read -p "text: " text
telnet server port (the user put this values on sh file directly)
helo
mail from: $from
rcpt to: $dest
data
from: $fromf <$from>
to: $destf <$dest>
subject: $subjct
$text
.

How can I do it?

1
  • 1
    It is better to use a program like mail(1) to do this, instead of futzing around with telnet(1). In any case, in today's increasingly paranoid world, you'll probably need to handle TLS to the mail server, and other messy details.
    – vonbrand
    Jul 24, 2015 at 0:21

1 Answer 1

3

I'm going to ignore the aspect of why you're doing this, and assume you already know the caveats — if not, know that many ISPs might block port 25 and some SMTP servers will block request from dynamic IP addresses.

A little-known feature of bash is that you can direct output to /dev/tcp/hostname/port and it'll connect to the server. So IF you're using bash, you can do something like:

cat > /dev/tcp/server/port <<EOF
HELO
MAIL FROM: $from
[...]
EOF
3
  • My goal is not to send spam or something like this.
    – eightShirt
    Jul 23, 2015 at 22:15
  • and IF you are using Linux (or bsd?)
    – user14755
    Jul 23, 2015 at 23:53
  • Why would that be part of it? I'm sure /dev/tcp is just a bash builtin; nothing to do with Linux. Unless you're saying bash haven't implemented the feature on other platforms.
    – Muzer
    Jul 24, 2015 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .