Issues getting any SMTP working in n8n instance (User Management emails or Email node)

Hi!
I’m currently running n8n behind a reverse proxy (Traefik) within a Scaleway VPC.
I have another server running baserow within the VPC that is able to send out emails fine via smtp (I’ve already set Scaleway up to allow smtp ports) I’ve also tested the credential in console using telnet and it works fine.

I’ve spent a lot of time troubleshooting and cannot seem to figure out the cause but it seems to be with n8n, I spun up a new n8n instance within the environment and got the same issue with the smtp node.

I am running in queue mode with 2 workers and 2 webhook processors but the docs mentioned nothing special about if you are using n8n scaling.

Describe the issue/error/question

Whenever I try to add a user or execute the email node I get a generic cannot send email error

What is the error message (if any)?

I’ve seen 2 differect errors when inviting a user:

0|n8n  | ERROR RESPONSE
0|n8n  | ResponseError: Failed to send email to [email protected]
0|n8n  |     at /home/n8n/.nodejs_global/lib/node_modules/n8n/dist/src/UserManagement/routes/users.js:320:19
0|n8n  |     at processTicksAndRejections (internal/process/task_queues.js:95:5)
0|n8n  |     at async /home/n8n/.nodejs_global/lib/node_modules/n8n/dist/src/ResponseHelper.js:91:26 {
0|n8n  |   httpStatusCode: 500
0|n8n  | }
0|n8n  | ERROR RESPONSE
0|n8n  | ResponseError: There is a problem with your SMTP setup! Connection timeout
0|n8n  |     at /home/n8n/.nodejs_global/lib/node_modules/n8n/dist/src/UserManagement/routes/users.js:28:23
0|n8n  |     at processTicksAndRejections (internal/process/task_queues.js:95:5)
0|n8n  |     at async /home/n8n/.nodejs_global/lib/node_modules/n8n/dist/src/ResponseHelper.js:91:26 {
0|n8n  |   httpStatusCode: 500
0|n8n  | }

And one when using the email node:

0|n8n      | ERROR RESPONSE
0|n8n      | ResponseError: Connection timeout
0|n8n      |     at /home/n8n/.nodejs_global/lib/node_modules/n8n/dist/src/UserManagement/routes/users.js:302:23
0|n8n      |     at processTicksAndRejections (internal/process/task_queues.js:95:5)
0|n8n      |     at async /home/n8n/.nodejs_global/lib/node_modules/n8n/dist/src/ResponseHelper.js:91:26 {
0|n8n      |   httpStatusCode: 500
0|n8n      | }

My env variables on the UI instance:

            WEBHOOK_URL: "https://n8n.domain.com",
            N8N_HOST:"n8n.internal.ip",
            N8N_PORT:"5678",
            N8N_PROTOCOL:"https",
            N8N_EDITOR_BASE_URL:"https://n8n.domain.com",
            N8N_LISTEN_ADDRESS: "0.0.0.0",
            N8N_ENDPOINT_WEBHOOK: "api",
            N8N_ENDPOINT_WEBHOOK_TEST: "api-test",
            N8N_ENDPOINT_WEBHOOK_WAIT: "api-wait",
            N8N_METRICS:true,
            N8N_PAYLOAD_SIZE_MAX:32,
            DB_TYPE:"postgresdb",
            DB_POSTGRESDB_DATABASE:"database", 
            DB_POSTGRESDB_HOST:"x.x.x.x",
            DB_POSTGRESDB_PORT:"port",
            DB_POSTGRESDB_USER:"username", 
            DB_POSTGRESDB_PASSWORD:"password", 
            NODE_FUNCTION_ALLOW_EXTERNAL:"uuid",
            QUEUE_BULL_REDIS_HOST:"x.x.x.x",
            QUEUE_BULL_REDIS_PORT:"port",
            QUEUE_BULL_REDIS_PASSWORD:"password",
            EXECUTIONS_MODE:"queue",
            N8N_DISABLE_PRODUCTION_MAIN_PROCESS:"true",
            N8N_SKIP_WEBHOOK_DEREGISTRATION_SHUTDOWN:"true",
            N8N_EMAIL_MODE:"smtp",
            N8N_SMTP_HOST:"smtp.gmail.com",
            N8N_SMTP_USER:"[email protected]",
            N8N_SMTP_PASS:"password",
            N8N_SMTP_SENDER:"[email protected]"

Information on your n8n setup

  • n8n version:0.169.0
  • Database you’re using : PostgreSQL
  • Running n8n with the execution process [own(default), main]:queue
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]:npm

Hi @Jaime_B, I am sorry for the trouble you’re having with this. This could be network related but unfortunately the logging here isn’t super helpful at the moment. I know @Jon has already passed this on as feedback to our product team, so let’s hope this changes soon.

Are you also having this problem when running n8n locally? For example when using docker run?

As for scaling/queue mode I do not have this mode configured unfortunately, but maybe @krynble can confirm whether this might have any impact?

Hi @MutedJam,

I think I’ve found the cause of the issue in someway!
I went and set up a basic n8n instance with caddy to reverse proxy and successfully sent an invite from that instance.

I then moved that instance into a Scaleway Virtual private network with a Public gateway attached and set up the correct NAT routing on the gateway (Basic :80 and :443) and now the invites and email node no longer work!

I then took an extra step and set up a very basic nodemailer setup to test that out and it seems that when I add my instance to a private network nodemailer timesout.
So I guess this is less of an n8n issue and more of a nodemailer issue! Sadly not found any resources that can help with fixing this :frowning:

Hey @Jaime_B,

Do you have the correct outbound routing in place for the mail server? The inbound routing shouldn’t make any difference so it could just be that port 465 isn’t allowed for outbound traffic.

I remember dealing with some issues in the past where some providers block it by default to help prevent spam so I took a look and found this How to send emails from your Instance

1 Like

Hi @jon,
Sadly I’ve already set that up within scaleway.
I have another server within the same network running Baserow that can happily email out, its using pythons mjmltcpserver. So I’m fairly certain the issue is with nodemailer & scaleway having a weird interaction.

I’m going to test out a few more idea I have and I have also contacted scaleway support to see if they have any clues. Will report back here if I find anything.

2 Likes

Hello @Jon!
An update.
I think I’ve found the problem!
For a bit of background: Scaleway uses both ipv4 and ipv6 but when you attach an instance to a private network with a public gateway although the gateway has an ipv4 address all outbound traffic is done via ipv6.
This is where the problem lies I believe, nodemailer doesn’t seem to be able to deal with ipv6 addresses or can’t resolve them .
I had a brief google but couldn’t find much useful about ipv6 and nodemailer so I’m a bit stuck.
Is there anyone within the n8n technical team that may be able to shine some light on this odd issue?

1 Like

Hey @Jaime_B,

So from what I understand Nodemailer uses the NodeJS dns.resolve() call to get the IP of the host (source: SMTP transport :: Nodemailer) so it could be that it is making the call and the DNS service is returning the IPv4 address and it is using that which should work but the network routing is not allowing it.

Looking a bit more into it what happens is it checks DNS and prefers IPv4, If it finds IPv4 it will use that if not it will then search for IPv6 to use that (source: Question about shared.resolveHostname logic · Issue #1041 · nodemailer/nodemailer · GitHub) it looks like someone did request having an option in the library to prefer ipv6 but it was closed with no action.

It sounds like this could be your problem though and one that I am not sure we can really do anything to fix (although I will have a think), Have you tried using a DNS service that only returns IPv6 that would in theory get it working unless Scaleway can also enable support for IPv4 as well which is still a valid option :slight_smile:

1 Like

Hi @Jon
I’ve had some luck testing something from what you’ve said! (Huge thanks for the support btw)

I used the ipv6 address of smtp.gmail.com as the host and set up

    tls: {
        servername: "smtp.gmail.com"
    },

as an extra option in the nodemailer.createTransport method of my nodemailer test script and it actually sent the email so I think your theory may be correct.

I think it would be a bit much to ask for the ability to be able to configure tls.servername within n8n env variables so I’m not sure theres much you guys can do. (unless that can be done) And tbf that wouldn’t fix the email node only the use management system.

I don’t know a huge amount about dns service and resolvers (enough to get by), I know I can change the dns service within scaleway but not sure how to find one that only returns ipv6 address google didn’t turn up much but that may be my poor wording of the query.

I have also contacted Scaleway to see if they’ve got any idea but thought I’d post an update anyway!

1 Like

Hello!
I have found the solution to the issue so wanted to share here incase anyone else comes across the same issue.
This is specific to Scaleway, in particular having n8n within a VPC, behind a public gateway!

The Cause of the issue: Currently Scaleways Public gateways do not support smtp so always block smtp ports! (Even if you enable them in the security settings, this is also not explicitly mentioned anywhere obvious).

The solution: Route traffic on 465, 587 and 25 through your servers public route instead of the gateway route, a fairly simple solution! The more detailed version is on scaleways slack in the public gateway channel (specific to ubuntu 20.04 but the idea is the same regardless of os): Link to solution thread
Also really appreciate the help here that guided me in the general.

I will note they are planning to support smtp on public gateways so this hopefully won’t always be an issue!

2 Likes

That is good to know, I wonder why they have a page telling you to open the ports if they still block it :thinking:

This will be a handy thread for anyone else using Scaleway, Nice work finally getting to the bottom of it.