mail sending using telnet in python

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


On Fri, 8 Jul 2005 07:49:25 +0100 (BST), praba kar <prabapython at yahoo.co.in> wrote:
> Dear All,
>       Normally we can send mail using
> telnet in linux. In the following way
> [~user]telnet Ipaddress 25
> mail from: raj at rajkumar.com
> 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

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



More information about the Python-list mailing list