Skip to content

Commit

Permalink
Merge branch 'bug.blank_username_in_settings' of dairiki/pyramid_mail…
Browse files Browse the repository at this point in the history
…er into pull/70
  • Loading branch information
mmerickel committed Dec 7, 2016
2 parents d66a42e + 5d1f5d3 commit 69d17a4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,11 @@ Changelog
Unreleased
----------

- Pull #70: If ``username`` and ``password`` are both set to the empty string,
``Mailer.from_settings``, now interprets them as being set to ``None``.
Previously, setting them to the empty string caused SMTP authentication
to be force with empty username and password.

- Pull #71: Add a ``content_id`` argument to the ``Attachment`` constructor
which allows you to set the Content-ID header so you can reference it from
an HTML body.
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -133,6 +133,8 @@ Contributors

- Mário Idival, 2015-05-21

- Geoffrey T. Dairiki, 2015-06-30

- Ingmar Steen, 2015-08-20

- Daniel Kraus, 2015-08-27
11 changes: 10 additions & 1 deletion pyramid_mailer/mailer.py
Expand Up @@ -246,7 +246,16 @@ def from_settings(cls, settings, prefix='mail.'):
if key in kwargs:
kwargs[key] = aslist(kwargs.get(key))

return cls(**kwargs)
username = kwargs.pop('username', None)
password = kwargs.pop('password', None)
if not (username or password):
# Setting both username and password to the empty string,
# causes repoze.sendmail.mailer.SMTPMailer to authenticate.
# This most likely makes no sense, so, in that case
# set username to None to skip authentication.
username = password = None

return cls(username=username, password=password, **kwargs)

def send(self, message):
"""Send a message.
Expand Down
8 changes: 8 additions & 0 deletions pyramid_mailer/tests/test_mailer.py
Expand Up @@ -248,6 +248,14 @@ def test_from_settings_with_str_values(self):
self.assertEqual(mailer.sendmail_mailer.sendmail_template,
['{sendmail_app}', '--option1', '--option2', '{sender}'])

def test_from_settings_with_empty_username(self):
settings = {'mymail.username': '',
'mymail.password': ''}
mailer = self._getTargetClass().from_settings(settings,
prefix='mymail.')
self.assertEqual(mailer.direct_delivery.mailer.username, None)
self.assertEqual(mailer.direct_delivery.mailer.password, None)

def test_send_immediately(self):
import socket
mailer = self._makeOne(host='localhost', port='28322')
Expand Down

0 comments on commit 69d17a4

Please sign in to comment.