Skip to content

smtplib SMTP.sendmail (TypeError: expected string or buffer) #52298

Closed

Description

@AllisonVollmann
BPO 8050
Nosy @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2010-03-08.13:46:43.643>
created_at = <Date 2010-03-03.15:00:15.839>
labels = ['invalid', 'type-bug', 'library']
title = 'smtplib SMTP.sendmail (TypeError: expected string or buffer)'
updated_at = <Date 2011-06-02.11:13:05.021>
user = 'https://bugs.python.org/AllisonVollmann'

bugs.python.org fields:

activity = <Date 2011-06-02.11:13:05.021>
actor = 'honyczek'
assignee = 'none'
closed = True
closed_date = <Date 2010-03-08.13:46:43.643>
closer = 'Allison.Vollmann'
components = ['Library (Lib)']
creation = <Date 2010-03-03.15:00:15.839>
creator = 'Allison.Vollmann'
dependencies = []
files = []
hgrepos = []
issue_num = 8050
keywords = []
message_count = 5.0
messages = ['100346', '100641', '100653', '120477', '137472']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'honyczek']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue8050'
versions = ['Python 2.6']

Activity

  1. AllisonVollmann commented on Mar 3, 2010

    AllisonVollmannmannequin
    MannequinAuthor

    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 sub
        return _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

  2. added
    type-crash
    on Mar 3, 2010
  3. added
    stdlib
    type-bug
    and removed
    type-crash
    on Mar 3, 2010
  4. AllisonVollmann commented on Mar 8, 2010

    AllisonVollmannmannequin
    MannequinAuthor

    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 :-)

  5. bitdancer commented on Mar 8, 2010

    @bitdancer
    Member

    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.

  6. bitdancer commented on Nov 5, 2010

    @bitdancer
    Member

    See bpo-10321 for a proposal to add Message support to smtplib.

  7. honyczek commented on Jun 2, 2011

    honyczekmannequin
    Mannequin

    Did you try to use this?
    q = quotedata(msg.as_string())

  8. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions