Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

SMTP email / gmail

default discord avatar
akacronos2 years ago
3

I'm trying to send emails using gmail smtp, I already create a pass for my smtp account (setting 2step verification and pass). Do I need to do something else? 😅



This is my config


payload.init({
  secret: process.env.PAYLOAD_SECRET,
  mongoURL: process.env.MONGODB_URI,
  express: app,
  onInit: () => {
    payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
  },
  email: {
    transportOptions: {
      host: process.env.SMTP_HOST,
      auth: {
        user: process.env.SMTP_USER,
        pass: process.env.SMTP_PASS,
      },
      port: 587,
      secure: true, // use TLS
      tls: {
        // do not fail on invalid certs
        rejectUnauthorized: false,
      },
    },
    fromName: 'hello',
    fromAddress: process.env.SMTP_FROM,
  },
});


I'm getting this errors:


There is an error with the email configuration you have provided. Error: 4041A9DD01000000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:355:
  • default discord avatar
    skry.2 years ago

    add service gmail, set secure to false and remove tls

      transportOptions: {
          service: "gmail",
          host: process.env.SMTP_HOST,
          auth: {
            user: process.env.SMTP_USER,
            pass: process.env.EMAIL_APP_PASS,
          },
          port: 587,
          secure: false,
        }, 
  • default discord avatar
    thiccaxe2 years ago

    Google requires SSL on email going out of gmail:



    If you connect using SSL or TLS, you can send email to anyone inside or outside of your organization using smtp.gmail.com as your SMTP server. This option requires you to authenticate with your Gmail or Google Workspace account and passwords

  • default discord avatar
    akacronos2 years ago

    Thanks a lot! This works 🙂

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.