docker-zulip icon indicating copy to clipboard operation
docker-zulip copied to clipboard

Server can't send emails and I'm getting ascii codec error message when troubleshooting

Open panomitrius opened this issue 4 years ago • 4 comments

I just configured this docker and managed to set it up alright. However I can't send emails, I've tried both SSL on 465 and TSL on 587 (using zoho email which works fine on a Rocket Chat server) and when I'm trouble shooting by accessing the zulip docker through a bash shell, and running su zulip -c "./manage.py send_test_email [email protected]" from root@e691fb5ad3a6:/home/zulip/deployments/current I'm getting this error message:

If you run into any trouble, read:

  https://zulip.readthedocs.io/en/latest/production/email.html#troubleshooting

The most common error is not setting `ADD_TOKENS_TO_NOREPLY_ADDRESS=False` when
using an email provider that doesn't support that feature.

Sending 2 test emails from:
  * [email protected]
Traceback (most recent call last):
  File "./manage.py", line 50, in <module>
    execute_from_command_line(sys.argv)
  File "/home/zulip/deployments/2020-12-12-17-23-45/zulip-py3-venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/zulip/deployments/2020-12-12-17-23-45/zulip-py3-venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/zulip/deployments/2020-12-12-17-23-45/zulip-py3-venv/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/zulip/deployments/2020-12-12-17-23-45/zulip-py3-venv/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/zulip/deployments/2020-12-12-17-23-45/zerver/management/commands/send_test_email.py", line 36, in handle
    send_mail("Zulip email test", message, sender, kwargs['email'])
  File "/home/zulip/deployments/2020-12-12-17-23-45/zulip-py3-venv/lib/python3.6/site-packages/django/core/mail/__init__.py", line 60, in send_mail
    return mail.send()
  File "/home/zulip/deployments/2020-12-12-17-23-45/zulip-py3-venv/lib/python3.6/site-packages/django/core/mail/message.py", line 306, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/zulip/deployments/2020-12-12-17-23-45/zulip-py3-venv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 103, in send_messages
    new_conn_created = self.open()
  File "/home/zulip/deployments/2020-12-12-17-23-45/zulip-py3-venv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 70, in open
    self.connection.login(self.username, self.password)
  File "/usr/lib/python3.6/smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "/usr/lib/python3.6/smtplib.py", line 630, in auth
    response = encode_base64(initial_response.encode('ascii'), eol='')
UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in position 29: ordinal not in range(128)

I've also tried to run it with "su zulip" and export LANG=C.UTF-8 but it doesn't help, getting the same error.

panomitrius avatar Dec 12 '20 19:12 panomitrius

I managed to get the script running without errors adding these 3 lines to manage.py: import codecs sys.stdout = codecs.getwriter('utf8')(sys.stdout) sys.stderr = codecs.getwriter('utf8')(sys.stderr)

after finding the suggestions here

However, manage.py send_test_email runs without errors, but I still don't get any emails.

panomitrius avatar Dec 13 '20 08:12 panomitrius

I realized that Zulip uses the email service different than for example Rocket Chat and that I can’t use it with it’s default settings with zoho email. However I could set it up through my local postfix server in relay mode (on the docker host).

panomitrius avatar Dec 13 '20 11:12 panomitrius

Monkey-patching sys.stdout and sys.stderr is certainly wrong; the error isn’t about printing something to stdout or stderr.

It looks like your problem matches https://bugs.python.org/issue29750 “smtplib doesn't handle unicode passwords”. If so, you can work around this by changing your email password to have only ASCII characters.

andersk avatar Dec 15 '20 07:12 andersk

Monkey-patching sys.stdout and sys.stderr is certainly wrong; the error isn’t about printing something to stdout or stderr.

It looks like your problem matches https://bugs.python.org/issue29750 “smtplib doesn't handle unicode passwords”. If so, you can work around this by changing your email password to have only ASCII characters.

Ok, that might work too, but for now everything with the manage-script works well, I haven't ran into any further problems with my "monkey patch"

panomitrius avatar Dec 16 '20 11:12 panomitrius