marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.
MIT License
279 stars 62 forks source link

Py3k: Sending mail over SMTP tries to decode `str` objects #59

Closed nphilipp closed 4 years ago

nphilipp commented 8 years ago
>>> from marrow.mailer import Mailer, Message
>>> mailer = Mailer({'transport': {'use': 'smtp', 'tls': 'no', 'host': 'mail.tiptoe.de'}})
>>> msg = Message(author='noreply@example.com', to='nils@tiptoe.de', subject='Test')
>>> mailer.start(); mailer.send(msg); mailer.stop()
<20160226084050.11315.29958@gibraltar.str.redhat.com> DEFERRED AttributeError
Traceback (most recent call last):
  File "/home/nils/.virtualenvs/igl-py3k/lib/python3.4/site-packages/marrow/mailer/transport/smtp.py", line 115, in send_with_smtp
    recipients = [addr.decode('utf-8') for addr in message.recipients.string_addresses]
  File "/home/nils/.virtualenvs/igl-py3k/lib/python3.4/site-packages/marrow/mailer/transport/smtp.py", line 115, in <listcomp>
    recipients = [addr.decode('utf-8') for addr in message.recipients.string_addresses]
AttributeError: 'str' object has no attribute 'decode'
    Mailer(manager=ImmediateManager, transport=SMTPTransport)

The code assumes an UTF-8 encoded, Python 2 str object which needs to be decoded into a unicode object. In Python 3, this is unnecessary.

kute commented 7 years ago

how to solve this in py3 ?

amcgregor commented 4 years ago

This was likely resolved long, long ago, with a PR from Nando.