Hi, I'm struggling with sending a 100mb text file using Python running on a Windows XP client.
I'm current running ActiveState Python 2.7.72 and it seems Python keeps failing with the following exception: Traceback (most recent call last): File "emailtest.py", line 32, in <module> send_mail("t...@example.com", [ "t...@example.com" ], "Test", "TEST",[ r"C:\100mbfile.txt"] , "127.0.0.1") File "emailtest.py", line 28, in send_mail smtp.sendmail(send_from, send_to, message) File "C:\Python27\lib\smtplib.py", line 725, in sendmail (code, resp) = self.data(msg) File "C:\Python27\lib\smtplib.py", line 492, in data self.send(q) File "C:\Python27\lib\smtplib.py", line 317, in send raise SMTPServerDisconnected('Server not connected') In order to isolate the problem, I'm currently running a test SMTP server on the same host as the client using the following command: python -m smtpd -n -c DebuggingServer localhost:25 I'm using this script for building/delivering the email: def send_mail(send_from, send_to, subject, text, files=[], server="localhost"): msg = MIMEMultipart() msg['From'] = send_from msg['To'] = COMMASPACE.join(send_to) msg['Date'] = formatdate(localtime=True) msg['Subject'] = subject msg.attach( MIMEText(text) ) for f in files: part = MIMEBase('application', "octet-stream") part.set_payload( open(f,"rb").read() ) Encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f)) msg.attach(part) message = msg.as_string() smtp = smtplib.SMTP(server) smtp.sendmail(send_from, send_to, message) smtp.close() send_mail("t...@example.com", ["t...@example.com"], "Test Subject", "Email Body", [ r"C:\100mbfile.txt"] , "localhost") I was able to deliver 20mb files with this script, but failed when trying 100mb files. It seems the code runs smoothly when I'm removing this line which encoded the part as base64: Encoders.encode_base64(part) I've notice the problem only occurs on my Windows XP, cause I was able to use the same code for delivering a 100mb file on a Windows 7 client. Using a sniffer I was able to ensure that the SMTP conversation is starting and get to the point where the client sends the "DATA" command, and then a few seconds later the client sends a "FIN" flagged packet to the server, which cause both ends to close the connection. Could you please advice what may cause this unexpected exception and how could it be fixed?
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32