problem with sending email

Haris Lekatsas lekatsas at
Wed Jul 4 04:55:56 CEST 2001

In article <qZj07.26346$he.1368759 at>, Steve Holden
>"Haris Lekatsas" <lekatsas at EE.Princeton.EDU> wrote in ...
>> This works thanks!
>> Unfortunately it makes my scripts less portable as the path to
>> sendmail has to be specified (not always at /usr/sbin/sendmail)
>> but this seems to be the only solution I have so far.
>> I wonder if python's smtplib is broken.
>Certainly not *that* broken. On Windows platforms it sends megabytes of mail
>for me every month, some of it single messages with 2MB zipfile attachments.
>Don't currently use it on Unix.
>I notice in your original code you assemble the message line-by-line,
>reading from a text file. You could think about
>a) Putting debug outputs in there to see what message length is being passed
>to SMPT.sendmail(), or
>b) Using read() to suck the whole thing in - if line endings are a problem
>you could use replace() to ensure they are correct.
>But you really should check what sendmail() is being given, so you know
>where to look next for the possible error.
> Steve
It seems sendmail is really getting the whole input. I am now printing msg and
i get the whole thing. Also the debugging level is set to 1. As before, running
it from the shell it will run fine, running it from the web as a cgi
script will only send 17,988 bytes of the text. However it will print that the
message was sent fine and the whole msg string will appear on screen from the
last print statement.
It might have something to do with the HTTP server...

#!/usr/bin/env python

import socket, smtplib

server = smtplib.SMTP()

msg = "From: " + "Haris Lekatsas <lekatsas at>" + "\012"
msg = msg + "To: " + "Haris Lekatsas <lekatsas at>" + "\012"
msg = msg + "Subject: " + "subject" + "\012"
fd = open('', 'r')
text = ''
text =

msg = msg + '\012' + text

tmp_output = server.sendmail("lekatsas at", "lekatsas at",
print "Error\n"

print "Content-type: text/html\n\n"
print msg

More information about the Python-list mailing list