inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.12k stars 739 forks source link

Email settings not configured #4473

Closed phil-ittech closed 1 year ago

phil-ittech commented 1 year ago

Deployment Method

Describe the problem*

Hello,

I am having issues configuring the email settings to connect to our on-prem exchange server.

I have configured the .env file with the following variables (Note - exchange does not require authentication internally)

INVENTREE_EMAIL_HOST INVENTREE_EMAIL_PORT INVENTREE_EMAIL_SENDER

However, when running the docker container, the 'System Information' screen reports that 'Email settings not configured. Under 'Global Settings' > 'Login Settings' a prompt shows at the top saying 'Outgoing email has not been configured. Some login and sign-up features may not work correctly!'

Apologies if I have missed something obvious in the documentation but I seem to be going round in circles currently. Any help that you could offer would be greatly appreciated. Thank you

Steps to Reproduce

  1. Stop the contain with docker compose down
  2. Edit .env file to include the email variables (as per https://docs.inventree.org/en/0.10.0/start/config/#email-settings)
  3. Starting the container with docker compose up -d

Further steps (Apologies, these might be all guesses at this stage)

  1. I have tried setting these within the configuration file (I believe saved here: volume/inventree-data/config.yaml to include host, port, sender, tls and ssl variables, however with no change.
  2. Feeling like I am missing a step, I am running docker compose run inventree-server invoke update
  3. I am now running 0.10.1 but with the same issue.

Relevant log output

No response

matmair commented 1 year ago

hi there @phil-ittech ! Have you checked if you can ping the Exchange server from within the docker container? Sometimes DNS resolving does not work with windows networks + docker. From past experience with Exchange, it might be required to pass an empty username/password combination and set email_sender. Also, NTML/Kerberos authentication will not work as your container is (probably) not joined to your domain.

SchrodingersGat commented 1 year ago

@phil-ittech as per this function:

https://github.com/inventree/InvenTree/blob/93a2d612e2d2f8581e083f62cc84fe8b65f0c275/InvenTree/InvenTree/status.py#L44

You will need to also specify the username EMAIL_HOST_USER and password EMAIL_HOST_PASSWORD

phil-ittech commented 1 year ago

Hello @matmair. Thank you for your reply, really appreciate it.

I have checked and I can ping the exchange server from the docker host and from the container directly. I can also telnet to the server on port 25.

I have added the following variables to the .env file, restarted the containers but with no luck.

INVENTREE_EMAIL_USERNAME INVENTREE_EMAIL_PASSWORD INVENTREE_EMAIL_TLS

A few of questons if I may:

root@f348c05495ce:/home/inventree/InvenTree/InvenTree# python3 status.py Traceback (most recent call last): File "/home/inventree/InvenTree/InvenTree/status.py", line 11, in <module> from django_q.models import Success File "/root/.local/lib/python3.9/site-packages/django_q/models.py", line 16, in <module> from django_q.conf import croniter File "/root/.local/lib/python3.9/site-packages/django_q/conf.py", line 31, in <module> class Conf: File "/root/.local/lib/python3.9/site-packages/django_q/conf.py", line 37, in Conf conf = settings.Q_CLUSTER File "/root/.local/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__ self._setup(name) File "/root/.local/lib/python3.9/site-packages/django/conf/__init__.py", line 63, in _setup raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Requested setting Q_CLUSTER, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

Does the above give any clues please?

@SchrodingersGat - With regards to 'EMAIL_HOST_USER' and 'EMAIL_HOST_PASSWORD' - is this in addition to INVENTREE_EMAIL_USERNAME and INVENTREE_EMAIL_PASSWORD please?

Many Thanks in advance.

SchrodingersGat commented 1 year ago

You have probably mis-configured your settings file, based on that error. Can you share a sanitized version here? Remove or redact any sensitive info.

matmair commented 1 year ago

The order is enviroment variable -> .env -> config.yaml -> database

phil-ittech commented 1 year ago

Thank you both for your replies and help.

@SchrodingersGat - here are my .env and config.yaml files

InvenTree env file

InvenTree config yaml file.txt

Thank you in advance

SchrodingersGat commented 1 year ago

Comprehensive docs for email setup are here - https://docs.inventree.org/en/latest/start/config/#email-settings

Unless you have removed the username and password values, they are empty in both your .env and config.yaml files (which is a problem)

phil-ittech commented 1 year ago

Hi @SchrodingersGat. Thanks the reply.

Both username and password values have been left blank on purpose as InvenTree will be connecting to our exchange server on an internal receive connector as 'Anonymous users' (as this is internal use we don't require authentication).

Are you saying however that these variables NEED to be populated please?

I will populate these now and report back.

Thank you

SchrodingersGat commented 1 year ago

Yes as per my link above in the is_email_configured method, these fields must be filled.. Might be a bug, as it doesn't allow for anon logins

phil-ittech commented 1 year ago

I have now authenticated with a domain user account and the 'Email Settings not configured' message has now gone from 'System Information'. Perfect.

However, I am now seeing SMTP authentication Server Error with the following data output

Traceback (most recent call last):

File "/home/inventree/InvenTree/InvenTree/forms.py", line 277, in send_mail
result = super().send_mail(template_prefix, email, context)

File "/root/.local/lib/python3.9/site-packages/allauth/account/adapter.py", line 140, in send_mail
msg.send()

File "/root/.local/lib/python3.9/site-packages/django/core/mail/message.py", line 284, in send
return self.get_connection(fail_silently).send_messages([self])

File "/root/.local/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
new_conn_created = self.open()

File "/root/.local/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 69, in open
self.connection.login(self.username, self.password)

File "/usr/local/lib/python3.9/smtplib.py", line 750, in login
raise last_exception

File "/usr/local/lib/python3.9/smtplib.py", line 739, in login
(code, resp) = self.auth(

File "/usr/local/lib/python3.9/smtplib.py", line 662, in auth
raise SMTPAuthenticationError(code, resp)

smtplib.SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful')

I will go off and troubleshoot this issue (as its likely to be something on my email server side) and report back as soon as I can to confirm what is going on here.

Thanks for your help with this.

matmair commented 1 year ago

I never even thought of anon mail servers, I have not had contact with non-cloud mail servers for years. @SchrodingersGat it might make sense to allow that. If I make a PR do you think we should merge?

phil-ittech commented 1 year ago

To confirm, the SMTP authentication error was related to an incorrect receive connector on the exchange server that was not correctly setup to accept from 'Exchange Users' (i.e. authenticated users) from an internal source.

Email is all working now from Inventree.

Thanks to both of you @SchrodingersGat @matmair for your swift replies and help.

Looking forward to using this system. Great work guys!

matmair commented 1 year ago

Great to hear, can we close this?

phil-ittech commented 1 year ago

Yes of course. Thanks!

SchrodingersGat commented 1 year ago

I never even thought of anon mail servers, I have not had contact with non-cloud mail servers for years. @SchrodingersGat it might make sense to allow that. If I make a PR do you think we should merge?

I don't think it hurts to allow for this option. I'd be happy to merge