marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

nphilipp opened this issue · comments

>>> 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.

commented

how to solve this in py3 ?

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