SMTP email / gmail

default discord avatar
akacronos
6 months 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
    6 months 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
    thiccaxe
    6 months 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
    akacronos
    6 months ago

    Thanks a lot! This works 🙂

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.