DarkflameUniverse/NexusDashboard

Sending SMTP via Mail Relay fails

DollarStoreCPU opened this issue · 3 comments

Hello,

I run NexusDashboard in a docker container.
I'm trying to get it to send SMTP on Port 25 to a MailEnable relay I have configured to accept unauthenticated SMTP from a list of IP addresses and send them Authenticated.

Please let me know if you need anything else, I've been scratching my head for a few days.

My research indicates that it's filtering the "mail port" as a string instead of an integer.
https://stackoverflow.com/questions/23079017/servname-not-supported-for-ai-socktype

My email-related enviroment variables are as follows:

  USER_ENABLE_CHANGE_PASSWORD: "True"  # Allow users to change their password
  USER_ENABLE_CHANGE_USERNAME: "False"  # Allow users to change their usernam
  USER_ENABLE_REGISTER: "True"  # Allow new users to register
  USER_ENABLE_EMAIL: "True"  # Register with Email WILL - DISABLE OTHER THINGS TOO
  USER_ENABLE_CONFIRM_EMAIL: "True"  # Force users to confirm their email
  USER_ENABLE_INVITE_USER: "True"  # Allow users to be invited
  USER_REQUIRE_INVITATION: "True"  # Only invited users may - WILL DISABLE REGISTRATION
  USER_ENABLE_FORGOT_PASSWORD: "True"   # Allow users to reset their password
  MAIL_SERVER: "10.1.1.2" - #IP address of mailEnable relay
  MAIL_PORT: 25
  MAIL_USE_SSL: "False"
  MAIL_USE_TLS: "False"
  MAIL_USERNAME: None
  MAIL_PASSWORD: None
  USER_EMAIL_SENDER_NAME: Lego Universe
  USER_EMAIL_SENDER_EMAIL: lego@emailaddress.com

Here is the log output when trying to invite a user.

raise EmailError('SMTP Connection error: Check your MAIL_SERVER and MAIL_PORT settings.')
socket.gaierror: [Errno -8] Servname not supported for ai_socktype
During handling of the above exception, another exception occurred:
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2070, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1515, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.8/site-packages/flask_user/user_manager.py", line 413, in invite_user_stub
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.invite_user_view()
  File "/usr/local/lib/python3.8/site-packages/flask_user/decorators.py", line 58, in decorator
    return view_function(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flask_user/user_manager__views.py", line 335, in invite_user_view
    self.email_manager.send_invite_user_email(current_user, user_invitation)
  File "/usr/local/lib/python3.8/site-packages/flask_user/email_manager.py", line 122, in send_invite_user_email
    self._render_and_send_email(
  File "/usr/local/lib/python3.8/site-packages/flask_user/email_manager.py", line 191, in _render_and_send_email
    self.user_manager.email_adapter.send_email_message(
  File "/usr/local/lib/python3.8/site-packages/flask_user/email_adapters/smtp_email_adapter.py", line 68, in send_email_message
Traceback (most recent call last):
flask_user.EmailError: SMTP Connection error: Check your MAIL_SERVER and MAIL_PORT settings.
    self.mail.send(message)
  File "/usr/local/lib/python3.8/site-packages/flask_user/email_adapters/smtp_email_adapter.py", line 64, in send_email_message
  File "/usr/local/lib/python3.8/site-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
    self.host = self.configure_host()
  File "/usr/local/lib/python3.8/site-packages/flask_mail.py", line 144, in __enter__
  File "/usr/local/lib/python3.8/site-packages/flask_mail.py", line 156, in configure_host
    host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
  File "/usr/local/lib/python3.8/smtplib.py", line 1048, in __init__
    SMTP.__init__(self, host, port, local_hostname, timeout,
  File "/usr/local/lib/python3.8/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.8/smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.8/smtplib.py", line 1054, in _get_socket
  File "/usr/local/lib/python3.8/socket.py", line 787, in create_connection
    new_socket = socket.create_connection((host, port), timeout,
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/local/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

Thanks for looking at this!

Another thing I noticed that could be contributing to the issue:

In Line 254 of init.py

app.config['MAIL_PORT'] = os.getenv( 'MAIL_USE_SSL', app.config['MAIL_PORT'] )

It looks like that it's setting MAIL_PORT in the app.config to MAIL_USE_SSL instead of environment variable, MAIL_PORT

Also, not sure if it matters, but it seems like the True/False statements for all of the settings, when using docker compose Environment Variables, are passing the values as strings instead of Booleans.
is it possible to force all those values as Booleans too?

whoops
probably the real issue, which was probably a copy-paste error on my part from when I set this up

should be fixed, for realzies