mail sending using telnet in python

Jorgen Grahn jgrahn-nntq at
Fri Jul 8 10:39:36 CEST 2005

On Fri, 8 Jul 2005 07:49:25 +0100 (BST), praba kar <prabapython at> wrote:
> Dear All,
>       Normally we can send mail using
> telnet in linux. In the following way
> [~user]telnet Ipaddress 25
> mail from: raj at
> 250 o.k(response of from commandline)

That is sometimes a very useful trick, but it doesn't always work. SMTP
requires CR-LF line endings, but your example only generates LF. Most mail
servers accept that, but they are not required to, and some don't (qmail?).

> Is it possible to run same thing same manner
> in python?  If possible kindly help me with
> specimen code.  Actually I gone through
> telnetlib module documentation but I cann't
> get solution for it.

When you use the telnet command to do it, you're simply abusing telnet to
get a command-line interface to a TCP socket -- it's really only intended to
talk to a telnet server. . If the 'netcat' utility was more widespread,
everyone would have used it instead.

When you use Python, it doesn't make sense to go through telnetlib. Use
module socket instead.

Or, simply use module smtplib, which also comes with example code (in Python
2.3, at least).

Have fun,

  // Jorgen Grahn <jgrahn@       Ph'nglui mglw'nafh Cthulhu
\X/      >   R'lyeh wgah'nagl fhtagn!

More information about the Python-list mailing list