Title: smtplib.sendmail() does not work for mails bigger than 64 KiB
Type: crash Severity: normal
Components: Core, Library Versions: Jython 2.7.1, Jython 2.7.2
Milestone: Jython 2.7.3
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: hariprasadbrungi, jeff.allen, r_walter, zyasoft
Priority: normal Keywords:

Created on 2019-11-25.14:51:35 by r_walter, last changed 2022-06-13.12:02:04 by jeff.allen.

File name Uploaded Description Edit Remove r_walter, 2019-11-25.14:51:34
double_rainbow.jpg r_walter, 2019-11-25.14:53:07 Picture used as attachment in the script r_walter, 2021-09-01.11:31:32
msg12796 (view) Author: Roland Walter (r_walter) Date: 2019-11-25.14:51:34
I tried to send an email with jython 2.7.1 and jython 2.7.2b2 with the attached The attached image is 85 KiB in size.
The OS is openSUSE Leap 15.1. The java version is 1.8.0_222.

The program fails with:

Traceback (most recent call last):
  File "", line 40, in <module>
    s.sendmail(sender, receiver, msg.as_string())
  File "/usr/local/jython2.7.1/Lib/", line 745, in sendmail
  File "/usr/local/jython2.7.1/Lib/", line 469, in rset
    return self.docmd("rset")
  File "/usr/local/jython2.7.1/Lib/", line 393, in docmd
    self.putcmd(cmd, args)
  File "/usr/local/jython2.7.1/Lib/", line 341, in putcmd
  File "/usr/local/jython2.7.1/Lib/", line 331, in send
    raise SMTPServerDisconnected('Server not connected')
smtplib.SMTPServerDisconnected: Server not connected

The log of the postfix mailserver shows:

2019-11-25T15:15:58.762073+01:00 dios postfix/smtpd[14421]: connect from localhost[]
2019-11-25T15:15:59.066917+01:00 dios postfix/smtpd[14421]: 104A2A08C1: client=localhost[]
2019-11-25T15:15:59.126283+01:00 dios postfix/cleanup[14434]: 104A2A08C1: message-id=<>
2019-11-25T15:20:59.227259+01:00 dios postfix/smtpd[14421]: timeout after DATA (65507 bytes) from localhost[]
2019-11-25T15:20:59.227865+01:00 dios postfix/smtpd[14421]: disconnect from localhost[] ehlo=1 mail=1 rcpt=1 data=0/1 commands=3/4

But the same program works with python.
msg12798 (view) Author: Roland Walter (r_walter) Date: 2019-11-25.14:53:07
I added the picture used as an attachment.
msg12826 (view) Author: Jeff Allen (jeff.allen) Date: 2019-12-13.07:37:01
We should be able to do better than that. Aiming for 2.7.2
msg12928 (view) Author: Jeff Allen (jeff.allen) Date: 2020-01-26.14:09:41
This is quite likely connected with the incomplete nature of our socket implementation, see for example, and I do not think a fix is feasible in the timescale of the 2.7.2 release.
msg13162 (view) Author: Roland Walter (r_walter) Date: 2021-08-24.16:26:13 has the solution for this.

Replace sendall in with the version given in

    def sendall(self, data, flags=0):
        chunk_size = 8192
        length = len(data)
        data_view = memoryview(data)
        idx = 0
        while idx < length:
            bytes_sent = self.send(data_view[idx:idx + chunk_size], flags=flags)
            idx += bytes_sent
msg13166 (view) Author: hari (hariprasadbrungi) Date: 2021-09-01.10:28:25

I have been following this bug and I have tried the solution provided.

Now a simple email without the attachments is failing with below error after updating the 

 File "E:\lib\Lib\", line 154, in urlopen
    return, data, timeout)
  File "E:\lib\Lib\", line 429, in open
    response = self._open(req, data)
  File "E:\lib\Lib\", line 446, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "E:\lib\Lib\", line 407, in _call_chain
    result = func(*args)
  File "E:\lib\Lib\", line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "E:\lib\Lib\", line 1195, in do_open
    h.request(req.get_method(), req.get_selector(),, headers)
  File "E:\lib\Lib\", line 1195, in do_open
    h.request(req.get_method(), req.get_selector(),, headers)
  File "E:\lib\Lib\", line 1042, in request
    self._send_request(method, url, body, headers)
  File "E:\lib\Lib\", line 1082, in _send_request
  File "E:\lib\Lib\", line 1038, in endheaders
  File "E:\lib\Lib\", line 882, in _send_output
  File "E:\lib\Lib\", line 858, in send
  File "E:\lib\Lib\", line 1464, in meth
    return getattr(self._sock,name)(*args)
  File "E:\lib\Lib\", line 1224, in sendall
    data_view = memoryview(data)
TypeError: cannot make memory view because object does not have the buffer interface
msg13168 (view) Author: Roland Walter (r_walter) Date: 2021-09-01.11:31:32
I could successfully execute with jython 2.7.2 on Windows 10 with Java openjdk 8u302.

Which jython version did you use? Your path of the library, is not the standard. Are you sure that is the one matching jython 2.7.2?

I attached my
msg13170 (view) Author: hari (hariprasadbrungi) Date: 2021-09-02.11:04:00
jython version is 2.7.2. 

I think the issue is from my custom email py script.

The script is working without changes and sends out the email with attachment less than 56 KB.

If i update the script and run my custom script, it fails with the error provided  before even reaching to the email part.

I will work my script and let you know
msg13230 (view) Author: Jeff Allen (jeff.allen) Date: 2022-06-13.12:02:04
Handle as and PR believed to fix.
Date User Action Args
2022-06-13 12:02:04jeff.allensetstatus: open -> closed
resolution: accepted -> out of date
messages: + msg13230
2021-09-02 11:04:00hariprasadbrungisetmessages: + msg13170
2021-09-01 11:31:33r_waltersetfiles: +
messages: + msg13168
2021-09-01 10:28:25hariprasadbrungisetnosy: + hariprasadbrungi
messages: + msg13166
2021-08-24 16:26:13r_waltersetmessages: + msg13162
2020-03-02 08:13:39jeff.allensetmilestone: Jython 2.7.3
2020-01-26 14:09:41jeff.allensetnosy: + zyasoft
messages: + msg12928
milestone: Jython 2.7.2 -> (no value)
2019-12-13 07:37:01jeff.allensetpriority: normal
resolution: accepted
messages: + msg12826
nosy: + jeff.allen
milestone: Jython 2.7.2
2019-11-25 14:53:07r_waltersetfiles: + double_rainbow.jpg
messages: + msg12798
2019-11-25 14:51:35r_waltercreate