Resend nodemailer - not sending emails

default discord avatar
eustachi0
2 weeks ago
6

It was working before, but I'm getting this error in development and production recently


There is an error with the email configuration you have provided. Error: Connection timeout

Failed to send mail to email@gmail.com, subject: Reset Your Password
    err: {
      "type": "Error",
      "message": "Connection timeout",
      "stack":
          Error: Connection timeout
              at SMTPConnection._formatError (/home/webarto/node_modules/nodemailer/lib/smtp-connection/index.js:790:19)
              at SMTPConnection._onError (/home/webarto/node_modules/nodemailer/lib/smtp-connection/index.js:776:20)
              at Timeout.<anonymous> (/home/webarto/node_modules/nodemailer/lib/smtp-connection/index.js:235:22)
              at listOnTimeout (node:internal/timers:573:17)
              at process.processTimers (node:internal/timers:514:7)
      "code": "ETIMEDOUT",
      "command": "CONN"
    }



// server.ts
import nodemailer from "nodemailer";
// resend
const transport = nodemailer.createTransport({
    host: "smtp.resend.com",
    secure: true,
    port: 465,
    auth: {
        user: "resend",
        pass: "re_password",
    },
});

...
await payload.init({
        secret: process.env.PAYLOAD_SECRET,
        express: app,
        email: {
            fromName: "Eustachio",
            fromAddress: "support@website.com",
            transport,
        },
        onInit: () => {
            payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
        },
...


I have checked firewalls for port 465 and it is open, I don't if there is another port or ip that is trying to communicate with the server and it isn't open



Any help would be great, please. Thank you

  • discord user avatar
    denolfe
    Payload Team
    2 weeks ago

    I would verify you can hit the smtp server/port from your env using telnet or netcat (nc)



    https://netcorecloud.com/tutorials/smtp-connection-from-command-line/
  • default discord avatar
    eustachi0
    2 weeks ago

    I'll try this today. Thanks Elliot



    I couldn't hit the smtp resend server using telnet, connection timeout. I think it's perhaps something to do with the smtp port and my server's firewalls



    Don't know how to fix it. I'll try with another provider, gmail perhaps to see if it works

  • discord user avatar
    denolfe
    Payload Team
    2 weeks ago

    Yeah, definitely seems like something in your environment - not payload related.

  • default discord avatar
    eustachi0
    2 weeks ago

    I got it working. It turns out that the server has ports 465 and 25 blocked by default to avoid malicious requests. I'm using

    port: 587

    and

    secure: false

    and it is working well now. Thanks for helping!

  • default discord avatar
    tyteen4a03
    2 weeks ago

    @denolfe is it possible to have Payload not require nodemailer to function? I just tried generating graphQL Schema and it was complaining that it cannot connect to nodemailer.io (I was offline)

  • discord user avatar
    denolfe
    Payload Team
    2 weeks ago

    @tyteen4a03 The ethereal nodemailer is defaulted if no other email transport is provided. You could look up how to do a "dummy" nodemailer transport that writes to stout and modify accordingly. I believe nodemailer has this example in their docs. (On mobile atm, otherwise I'd link you)

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.