Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bug: Anonymous SMTP authentication fails #7103

Closed
1 task done
aretaon opened this issue Nov 27, 2023 · 10 comments · Fixed by #8412
Closed
1 task done

🐛 Bug: Anonymous SMTP authentication fails #7103

aretaon opened this issue Nov 27, 2023 · 10 comments · Fixed by #8412
Assignees

Comments

@aretaon
Copy link

aretaon commented Nov 27, 2023

Please confirm if bug report does NOT exists already ?

  • I confirm there is no existing issue for this

Steps to reproduce ?

Use the SMTP App to configure sending mails to internal web server that accepts anonymous authentication via Port 465.
Enter server hostname, from and smtp port, leave the username and password fields blank and click on "test".
Nocodb will inform that "SMTP test failed, please check server log for more details." and the log will state

response: '535 5.7.8 Error: authentication failed: authentication failure',

This is possibly related to #5559 but reopened here as new issue for better reference.

Desired Behavior

The SMTP app sends an email via anonymous authentication (see #520) and does not produce an error.

Project Details

NocoDB used as docker: yes
NocoDB version: "nocodb/nocodb:latest"
Database used: mysql
OS: Ubuntu 22.04

Detailed log:

Error: SMTP test failed, please check server log for more details.
    at SMTP.test (/usr/src/app/docker/main.js:2:1462617)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async PluginsService.pluginTest (/usr/src/app/docker/main.js:2:1684404)
    at async PluginsController.pluginTest (/usr/src/app/docker/main.js:2:435331)
SMTP test error ::  Error: Invalid login: 535 5.7.8 Error: authentication failed: authentication failure
    at SMTPConnection._formatError (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:790:19)
    at SMTPConnection._actionAUTHComplete (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:1564:34)
    at SMTPConnection.<anonymous> (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:546:26)
    at SMTPConnection._processResponse (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:969:20)
    at SMTPConnection._onData (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:755:14)
    at SMTPConnection._onSocketData (/usr/src/app/node_modules/nodemailer/lib/smtp-connection/index.js:193:44)
    at TLSSocket.emit (node:events:514:28)
    at TLSSocket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9) {
  code: 'EAUTH',
  response: '535 5.7.8 Error: authentication failed: authentication failure',
  responseCode: 535,
  command: 'AUTH PLAIN'

Attachments

No response

@Zeoic
Copy link

Zeoic commented Jan 23, 2024

I am having the same issue in our environment. We have a local only SMTP relay setup to allow anonymous requests, but get this same error in nocodb. Did you end up finding a way around this?

@aretaon
Copy link
Author

aretaon commented Jan 29, 2024

No so far I did not solve this. There were other things with priority in the meantime but I am still very keen on getting this running.
Please let me know if you manage!

@Zeoic
Copy link

Zeoic commented Jan 30, 2024

I spent a few more hours trying then eventually gave up and used Office365 directly with their SMTP service. We would have much preferred to use our relay which is already set up how we like it, but that wasn't in the cards it seems.

@MarleTangible
Copy link

I was able to resolve the issue by adding a name parameter with the domain to the nodemailer config. In my case I manually input the domain into the compiled main.js file. Nodemailer stmp documentation states that name is an optional hostname that defaults to hostname of the machine.

Would it be possible to add the name as an input field or set a default value that is derived from the from address?

const config = {
      name: 'your-domain.com', 
      host: this.input?.host,
      ...
}

The idea came from a related discussion on the NodeBB community.

@aretaon
Copy link
Author

aretaon commented May 6, 2024

Thanks @MarleTangible for linking this here. Indeed adding the name attribute alone did not help, I additionally had to remove the authentication attribute to allow anonymous authentication.

First modification as suggested:

if (process.env.NC_SMTP_FROM && process.env.NC_SMTP_HOST && process.env.NC_SMTP_PORT) {
    const e = await E.default.getPluginByTitle(y.default.title);
    await E.default.update(e.id, {
        active: !0,
        input: JSON.stringify({
            from: process.env.NC_SMTP_FROM,
            name: 'my-domain.name',
        })
    })

Second modification:

async init() {
    var e, t, a, i, r, l, c, d, u, p, m;
    const _ = {
        ...
        // remove the following lines
        auth: {
            user: null === (u = this.input) || void 0 === u ? void 0 : u.username,
            pass: null === (p = this.input) || void 0 === p ? void 0 : p.password
        },
        ...
    };
    this.transporter = s.default.createTransport(_)
}

To avoid doing this manually all the time I added the following commands to my update script

docker exec -t -i mysql_nocodb_1 sed -i -e "s/from:process.env.NC_SMTP_FROM,host:process.env.NC_SMTP_HOST/from:process.env.NC_SMTP_FROM,name:'my-domain.name',host:process.env.NC_SMTP_HOST/g" docker/main.js
docker exec -t -i mysql_nocodb_1 sed -i -e "s/d.ignoreTLS),auth:{user:null===(u=this.input)||void 0===u?void 0:u.username,pass:null===(m=this.input)||void 0===m?void 0:m.password},tls:/d.ignoreTLS),tls:/g" docker/main.js

From my side, I can live with this solution,. However, I would very much welcome if future versions of NocoDB would include the option for anonymous authentication.

@MarleTangible
Copy link

@aretaon Somehow the name parameter on its own worked for me. I had to configure the SMTP as below though which didn't make much sense to me at the time. Maybe the changes you made about removing the authentication solves this issue.

And this is the code I had to replace:
ignoreTLS),auth:{
ignoreTLS),name:'my-domain.com',auth:{

I believe the sed command would look like this:
"s/ignoreTLS),auth:{/ignoreTLS),name:'my-domain.com',auth:{/g"

image

@aretaon
Copy link
Author

aretaon commented May 6, 2024

@MarleTangible Thanks for pointing out the correct position of the name attribute. Nevertheless, I still have to remove the authentication to get it working for me. The SMTP server I use requires implicit TLS over port 465.
image

@DarkPhoenix2704
Copy link
Member

@MarleTangible @aretaon Can you try this docker build?

docker run -d -p 8888:8080 nocodb/nocodb-timely:0.205.0-pr-8412-20240506-1153

@MarleTangible
Copy link

@DarkPhoenix2704 it worked for me.

image

Would it be possible to rename the name field to domain or something similar and swap its place with the host? Here's why, despite knowing what the enter, I made the mistake of entering the smtp server details into the name field and I presume this is going to be a very common mistake for any newcomers as well.

From Address: 
From Domain: 
SMTP Server: 
SMTP Port: 
Use Secure Connection: 
Ignore TLS Errors: 
Reject Unauthorized: 
Username: 
Password: 

@DarkPhoenix2704
Copy link
Member

Updated.

This pr will fix the issue

#8412

@DarkPhoenix2704 DarkPhoenix2704 self-assigned this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Closed
Development

Successfully merging a pull request may close this issue.

5 participants