You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
smtplib SMTP.sendmail (TypeError: expected string or buffer) #52298
When call SMTP.sendmail (with simple sendmail local sent and with smtp auth), the follow exception be raised (with debug output):
send: 'mail FROM:<xxx> size=5\r\n'
reply: '250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<xxx>\r\n'
reply: '250 2.1.5 Ok\r\n'
reply: retcode (250); Msg: 2.1.5 Ok
send: 'data\r\n'
reply: '354 End data with <CR><LF>.<CR><LF>\r\n'
reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>
data: (354, 'End data with <CR><LF>.<CR><LF>')
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
s.sendmail(to, to, msg)
File "C:\Python26\lib\smtplib.py", line 710, in sendmail
(code,resp) =self.data(msg)
File "C:\Python26\lib\smtplib.py", line 474, in data
q = quotedata(msg)
File "C:\Python26\lib\smtplib.py", line 157, in quotedata
re.sub(r'(?:\r\n|\n|\r(?!\n))', CRLF, data))
File "C:\Python26\lib\re.py", line 151, in subreturn _compile(pattern, 0).sub(repl, string, count)
TypeError: expected string or buffer
This error appear because 'data' isn't an string object, just replacing "q = quotedata(msg)" for "q = quotedata(str(msg))" (in Python26\lib\smtplib.py:474) solves the problem, but i can't understand how this simple mistake does not be noticed
Teste in:
Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14)
[GCC 4.3.2] on linux2,
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
On the other hand, having a facility somewhere in the stdlib to pass a Message object to SMTP sendmail would be handy. I've made a note of this in my working notes for email6 to see if there's something we want to do about it.
Activity
AllisonVollmann commentedon Mar 3, 2010
When call SMTP.sendmail (with simple sendmail local sent and with smtp auth), the follow exception be raised (with debug output):
send: 'mail FROM:<xxx> size=5\r\n'
reply: '250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<xxx>\r\n'
reply: '250 2.1.5 Ok\r\n'
reply: retcode (250); Msg: 2.1.5 Ok
send: 'data\r\n'
reply: '354 End data with <CR><LF>.<CR><LF>\r\n'
reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>
data: (354, 'End data with <CR><LF>.<CR><LF>')
This error appear because 'data' isn't an string object, just replacing "q = quotedata(msg)" for "q = quotedata(str(msg))" (in Python26\lib\smtplib.py:474) solves the problem, but i can't understand how this simple mistake does not be noticed
Teste in:
Python 2.5.2 (r252:60911, Jan 24 2010, 14:53:14)
[GCC 4.3.2] on linux2,
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
AllisonVollmann commentedon Mar 8, 2010
i believe which the parameter "msg" must be referenced as a string type when called "sendmail" nor as an MIME[Message, Multipart, Text, Base, Audio]
and this is obvious way to do it. but i'm not Dutch :-)
bitdancer commentedon Mar 8, 2010
On the other hand, having a facility somewhere in the stdlib to pass a Message object to SMTP sendmail would be handy. I've made a note of this in my working notes for email6 to see if there's something we want to do about it.
bitdancer commentedon Nov 5, 2010
See bpo-10321 for a proposal to add Message support to smtplib.
honyczek commentedon Jun 2, 2011
Did you try to use this?
q = quotedata(msg.as_string())