Missing default for EMAIL SERVER #3424

Closed
opened 2025-12-29 18:29:00 +01:00 by adam · 2 comments
Owner

Originally created by @netsandbox on GitHub (Feb 28, 2020).

Environment

  • Python version: 3.6.9
  • NetBox version: 2.7.7

Steps to Reproduce

  1. try to send email from NetBox without EMAIL dict in configuration.py

Expected Behavior

Email is send.

Observed Behavior

Email is not send.

NetBox doesn't set a default value for EMAIL_HOST:
bdf9857e6f/netbox/netbox/settings.py (L215-L221)

As the documentation says, EMAIL is an optional setting, I would expect NetBox sending an email without setting the EMAIL configuration.

I suggest setting 'localhost' as default for EMAIL SERVER.

Originally created by @netsandbox on GitHub (Feb 28, 2020). ### Environment * Python version: 3.6.9 * NetBox version: 2.7.7 ### Steps to Reproduce 1. try to send email from NetBox without EMAIL dict in configuration.py ### Expected Behavior Email is send. ### Observed Behavior Email is not send. NetBox doesn't set a default value for EMAIL_HOST: https://github.com/netbox-community/netbox/blob/bdf9857e6f3d0803bb1f0e6d39658af583647540/netbox/netbox/settings.py#L215-L221 As the documentation says, EMAIL is an optional setting, I would expect NetBox sending an email without setting the EMAIL configuration. I suggest setting 'localhost' as default for EMAIL SERVER.
adam closed this issue 2025-12-29 18:29:00 +01:00
Author
Owner

@jeremystretch commented on GitHub (Feb 28, 2020):

There is no logical default for an email server. You need to specify one that you have access to.

@jeremystretch commented on GitHub (Feb 28, 2020): There is no logical default for an email server. You need to specify one that you have access to.
Author
Owner

@netsandbox commented on GitHub (Feb 28, 2020):

It is quite common to setup a local MTA like postfix, which is configured to forward email to the company mail servers. 'localhost' would work in this cases.

Setting 'localhost' for EMAIL SERVER in netbox/netbox/settings.py wouldn't change anything for the default installation, because it is already set in 3538eeda14/netbox/netbox/configuration.example.py (L105-L113)

Also if you set ADMIN and not EMAIL SERVER in configuration.py, you get the following tracebacks:

Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 82, in close
    self.connection.quit()
  File "/usr/lib/python3.6/smtplib.py", line 984, in quit
    res = self.docmd("quit")
  File "/usr/lib/python3.6/smtplib.py", line 420, in docmd
    self.putcmd(cmd, args)
  File "/usr/lib/python3.6/smtplib.py", line 367, in putcmd
    self.send(str)
  File "/usr/lib/python3.6/smtplib.py", line 359, in send
    raise SMTPServerDisconnected('please run connect() first')
smtplib.SMTPServerDisconnected: please run connect() first
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.6/site-packages/gunicorn/workers/gthread.py", line 271, in handle
    keepalive = self.handle_request(req, conn)
  File "/opt/netbox/venv/lib/python3.6/site-packages/gunicorn/workers/gthread.py", line 320, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 141, in __call__
    response = self.get_response(request)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 81, in get_response
    request=request,
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/utils/log.py", line 228, in log_response
    exc_info=exc_info,
  File "/usr/lib/python3.6/logging/__init__.py", line 1337, in error
    self._log(ERROR, msg, args, **kwargs)
  File "/usr/lib/python3.6/logging/__init__.py", line 1444, in _log
    self.handle(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 1454, in handle
    self.callHandlers(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 1516, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python3.6/logging/__init__.py", line 865, in handle
    self.emit(record)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/utils/log.py", line 122, in emit
    self.send_mail(subject, message, fail_silently=True, html_message=html_message)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/utils/log.py", line 125, in send_mail
    mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/__init__.py", line 101, in mail_admins
    mail.send(fail_silently=fail_silently)
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/message.py", line 291, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 114, in send_messages
    self.close()
  File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 87, in close
    self.connection.close()
  File "/usr/lib/python3.6/smtplib.py", line 977, in close
    sock = self.sock
AttributeError: 'SMTP' object has no attribute 'sock'

It isn't quite easy to find the real problem with this traceback information.
I think there should be at least a comment for the ADMIN config option, that you also have to set the EMAIL config option.

@netsandbox commented on GitHub (Feb 28, 2020): It is quite common to setup a local MTA like postfix, which is configured to forward email to the company mail servers. 'localhost' would work in this cases. Setting 'localhost' for EMAIL SERVER in netbox/netbox/settings.py wouldn't change anything for the default installation, because it is already set in https://github.com/netbox-community/netbox/blob/3538eeda14a5ba1921299f2742593f0b9e434807/netbox/netbox/configuration.example.py#L105-L113 Also if you set ADMIN and not EMAIL SERVER in configuration.py, you get the following tracebacks: ``` Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 82, in close self.connection.quit() File "/usr/lib/python3.6/smtplib.py", line 984, in quit res = self.docmd("quit") File "/usr/lib/python3.6/smtplib.py", line 420, in docmd self.putcmd(cmd, args) File "/usr/lib/python3.6/smtplib.py", line 367, in putcmd self.send(str) File "/usr/lib/python3.6/smtplib.py", line 359, in send raise SMTPServerDisconnected('please run connect() first') smtplib.SMTPServerDisconnected: please run connect() first During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.6/site-packages/gunicorn/workers/gthread.py", line 271, in handle keepalive = self.handle_request(req, conn) File "/opt/netbox/venv/lib/python3.6/site-packages/gunicorn/workers/gthread.py", line 320, in handle_request respiter = self.wsgi(environ, resp.start_response) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 141, in __call__ response = self.get_response(request) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 81, in get_response request=request, File "/opt/netbox/venv/lib/python3.6/site-packages/django/utils/log.py", line 228, in log_response exc_info=exc_info, File "/usr/lib/python3.6/logging/__init__.py", line 1337, in error self._log(ERROR, msg, args, **kwargs) File "/usr/lib/python3.6/logging/__init__.py", line 1444, in _log self.handle(record) File "/usr/lib/python3.6/logging/__init__.py", line 1454, in handle self.callHandlers(record) File "/usr/lib/python3.6/logging/__init__.py", line 1516, in callHandlers hdlr.handle(record) File "/usr/lib/python3.6/logging/__init__.py", line 865, in handle self.emit(record) File "/opt/netbox/venv/lib/python3.6/site-packages/django/utils/log.py", line 122, in emit self.send_mail(subject, message, fail_silently=True, html_message=html_message) File "/opt/netbox/venv/lib/python3.6/site-packages/django/utils/log.py", line 125, in send_mail mail.mail_admins(subject, message, *args, connection=self.connection(), **kwargs) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/__init__.py", line 101, in mail_admins mail.send(fail_silently=fail_silently) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/message.py", line 291, in send return self.get_connection(fail_silently).send_messages([self]) File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 114, in send_messages self.close() File "/opt/netbox/venv/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 87, in close self.connection.close() File "/usr/lib/python3.6/smtplib.py", line 977, in close sock = self.sock AttributeError: 'SMTP' object has no attribute 'sock' ``` It isn't quite easy to find the real problem with this traceback information. I think there should be at least a comment for the ADMIN config option, that you also have to set the EMAIL config option.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3424