Connecting Gmail SMTP with

Hi everyone,

New to I have a node ts express server hosted in and a separate client side hosted in cloudflare. I am using nodemailer to send emails from the clientside to my server and this is working well locally. However whenever I try to make calls to my deployed address:

await"", values);

I get the error:
Error sending email: connect ECONNREFUSED

Can someone help me out with this? I’m using nodemailer and google’s smtp.

Not a node expert here, put you posted a code fragment that seemingly connects with on port 443, but your error message says something related to IP address 127.0.01 (which, in normal circumstances, is not mapped to and port 587.

Can you explain your setup a little more?

How did you reach the conclusion that its on port 443?

Yes, I can elaborate and share my config.
This is my toml file, I have added the ports there (checked a few issues related to this) but it doesnt work.


  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 0
  processes = ["app"]

  internal_port = 25
  protocol = "tcp"

    port = 25

    handlers = ["tls", "http"]
    port = 465

    port = 587

Then on my config file for the smtp i have the following:

import dotenv from "dotenv";

export const emailConfig = {
  service: process.env.SMTP_SERVICE,
  port: Number(process.env.SMTP_PORT),
  secure: false,
  auth: {
    user: process.env.SMTP_USERNAME,
    pass: process.env.SMTP_PASSWORD,

export const receiverEmail = process.env.RECEIVER_EMAIL;

My serverside also as the method post(/api/submitForm) configurated.

Basically the .env PORT is 465 (it was 587 before), am I missing something else that I need to config?

I don’t know the inner workings of nodemailer, so I interpreted what I saw, and that was the axios https request (https = 443).

But it seems like the node server is trying to access host which leads me to believe that you are actually not using Google’s SMTP server.

Does your .env contain SMTP_SERVICE (check the value)? Is the .env included in the Docker image or is it ignored / not copied?

If you connect to your VM via fly console ssh, can you find your .env there and take a look it its contents?

My .env has the following config:


Does your .env contain SMTP_SERVICE (check the value)? Is the .env included in the Docker image or is it ignored / not copied?

Do you mean in the dockerfile? I’ve realised now that the dockerignore has .env in the ignore list.

Edit: I have added a `ENV PORT=465" to the dockerfile and the error seemed to have been fixed, now it displays a different one:

Error sending email: Missing credentials for "PLAIN"

So I’m checking the dockerfile again.

If .env is in your .dockerignore, then it won’t be included in your Docker image. You can set the env vars via fly.toml or secrets (fly secrets set ...). See the docs:

1 Like

Thank you. So this is now working.

Like you said the problem here was that my .env values were not being taken in consideration in my dockerfile. I configured the secrets and it worked. Thank you very much :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.