openlibhums / janeway

A web-based platform for publishing journals, preprints, conference proceedings, and books
https://janeway.systems/
GNU Affero General Public License v3.0
177 stars 65 forks source link

SMTP Exception: please run connect() first #2520

Closed jscottbranson closed 3 years ago

jscottbranson commented 3 years ago

Describe the bug An exception is raised anytime janeway attempts to send email using the SMTP backend. I've set EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, and EMAIL_USE_TLS in my src/core/settings.py (and also in janeway_global_settings.py - I'm guessing that settings.py overrides global_settings.py, though - please correct me if I'm wrong).

I'm not particularly familiar with Django's SMTP backend, so it is entirely possible this is user error, in which case I apologize for the inconvenience.

Janeway version 1.4-RC-4 Server is running Debian 10 (kernel 4.19.0-18) with Python 3.7.3

To Reproduce Steps to reproduce the behavior:

  1. New janeway install with above email settings in src/core/settings.py
  2. User goes to submit manuscript
  3. Exception is raised and user gets a "Server Error"

Expected behavior Connect to the remote server and send the mail.

Trace

WARNING 2021-10-16 09:51:57,019 setting_handler P:2932 T:140307177658112 [ADS] Passing 'create' to get_setting has been deprecated in in favour of returning the default value
ERROR 2021-10-16 09:51:57,026 exception P:2932 T:140307177658112 Internal Server Error: /ADS/submit/2/review/
Traceback (most recent call last):
  File "/home/user/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/user/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/home/user/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/user/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/user/.virtualenvs/janeway/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/user/janeway/src/submission/decorators.py", line 31, in submission_is_enabled_wrapper
    return func(request, *args, **kwargs)
  File "/home/user/janeway/src/security/decorators.py", line 566, in wrapper
    return func(request, *args, **kwargs)
  File "/home/user/janeway/src/submission/views.py", line 534, in submit_review
    **kwargs
  File "/home/user/janeway/src/events/logic.py", line 256, in raise_event
    event_return = [func(**kwargs) for func in Events._hooks[event_name]]
  File "/home/user/janeway/src/events/logic.py", line 256, in <listcomp>
    event_return = [func(**kwargs) for func in Events._hooks[event_name]]
  File "/home/user/janeway/src/utils/transactional_emails.py", line 374, in send_submission_acknowledgement
    log_dict=log_dict,
  File "/home/user/janeway/src/utils/notify_helpers.py", line 28, in send_email_with_body_from_setting_template
    notify.notification(**notify_contents)
  File "/home/user/janeway/src/utils/notify.py", line 21, in notification
    [func(**kwargs) for func in settings.NOTIFY_FUNCS]
  File "/home/user/janeway/src/utils/notify.py", line 21, in <listcomp>
    [func(**kwargs) for func in settings.NOTIFY_FUNCS]
  File "/home/user/janeway/src/utils/notify_plugins/notify_email.py", line 90, in notify_hook
    response = send_email(subject, to, html, request.journal, request, bcc, cc, attachment)
  File "/home/user/janeway/src/utils/notify_plugins/notify_email.py", line 62, in send_email
    return msg.send()
  File "/home/user/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/mail/message.py", line 348, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/user/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 104, in send_messages
    new_conn_created = self.open()
  File "/home/user/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 69, in open
    self.connection.starttls(keyfile=self.ssl_keyfile, certfile=self.ssl_certfile)
  File "/usr/lib/python3.7/smtplib.py", line 749, in starttls
    self.ehlo_or_helo_if_needed()
  File "/usr/lib/python3.7/smtplib.py", line 600, in ehlo_or_helo_if_needed
    if not (200 <= self.ehlo()[0] <= 299):
  File "/usr/lib/python3.7/smtplib.py", line 440, in ehlo
    self.putcmd(self.ehlo_msg, name or self.local_hostname)
  File "/usr/lib/python3.7/smtplib.py", line 367, in putcmd
    self.send(str)
  File "/usr/lib/python3.7/smtplib.py", line 359, in send
    raise SMTPServerDisconnected('please run connect() first')
smtplib.SMTPServerDisconnected: please run connect() first
ajrbyers commented 3 years ago

It’s possible the port is not correct for the settings you’ve used but I can tell you this isn’t a Janeway bug but a problem with the SMTP server.

jscottbranson commented 3 years ago

After messing around with my config, I can confirm the issue was indeed user error.

Can you tell me how to get janeway to reread my settings.py? It seems like it doesn't happen automatically when wsgi gets called. I tried running python3 manage.py update_defaults, without effect.