payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
25.72k stars 1.64k forks source link

Email transport verify should be called upon payload.init and not on build #8251

Closed yobottehg closed 2 months ago

yobottehg commented 2 months ago

Link to reproduction

No response

Environment Info

Binaries:
  Node: 20.17.0
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  payload: 3.0.0-beta.106
  next: 15.0.0-canary.106
  @payloadcms/db-postgres: 3.0.0-beta.106
  @payloadcms/email-nodemailer: 3.0.0-beta.106
  @payloadcms/graphql: 3.0.0-beta.106
  @payloadcms/next/utilities: 3.0.0-beta.106
  @payloadcms/plugin-form-builder: 3.0.0-beta.106
  @payloadcms/plugin-redirects: 3.0.0-beta.106
  @payloadcms/plugin-search: 3.0.0-beta.106
  @payloadcms/plugin-seo: 3.0.0-beta.106
  @payloadcms/richtext-lexical: 3.0.0-beta.106
  @payloadcms/translations: 3.0.0-beta.106
  @payloadcms/ui/shared: 3.0.0-beta.106
  react: 19.0.0-rc-06d0b89e-20240801
  react-dom: 19.0.0-rc-06d0b89e-20240801
Operating System:
  Platform: linux
  Arch: arm64
  Version: #1 SMP Mon Aug 12 08:47:01 UTC 2024
  Available memory (MB): 15975
  Available CPU cores: 8

Describe the Bug

Our project uses runtime environment variables for the nodeMailer:

email: nodemailerAdapter({
    defaultFromAddress: process.env['SMTP_FROM_ADDRESS'] ?? '',
    defaultFromName: process.env['SMTP_FROM_NAME'] ?? '',
    transport: nodemailer.createTransport({
      host: process.env['SMTP_HOST'] ?? '',
      port: Number.isInteger(smtpPort) ? smtpPort : 0,
      secure: process.env['SMTP_TLS'] === 'true',
      auth: {
        user: process.env['SMTP_USER'] ?? '',
        pass: process.env['SMTP_PASS'] ?? '',
      },
    }),
  }),

However during the build step the following error is thrown because these variables are not existent during build:

#19 52.31 {
#19 52.31   err: Error: connect ECONNREFUSED 127.0.0.1:587
#19 52.31       at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16)
#19 52.31       at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
#19 52.31     errno: -111,
#19 52.31     code: 'ESOCKET',
#19 52.31     syscall: 'connect',
#19 52.31     address: '127.0.0.1',
#19 52.31     port: 587,
#19 52.31     command: 'CONN'
#19 52.31   },
#19 52.31   msg: 'Error verifying Nodemailer transport.'
#19 52.31 }

Reproduction Steps

  1. Use a mail adapter with environment variables which are not available during build.
  2. Run the build.

Adapters and Plugins

email-nodemailer

yobottehg commented 2 months ago

To whoever comes here:

nodeMailer has a build in verification which is run on build. This can be disabled by setting skipVerify: true in the nodeMailer settings.

github-actions[bot] commented 1 month ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.