wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
12.93k stars 1.15k forks source link

No way to set neither the secure nor requireTLS attributes on the configuration for nodermailer's createTransport #2164

Closed nicolasf10 closed 2 weeks ago

nicolasf10 commented 3 weeks ago

Describe the bug I'm having issues setting up SMTP using AWS' SES (Simple Email Service), and after researching the issue I've realized that one potential fix is correctly setting the secure field on the configuration for nodemailer's createTransport function.

export function initSmtpEmailSender(config: SMTPEmailProvider): EmailSender {
  const transporter = createTransport({
    host: config.host,
    port: config.port,
    auth: {
      user: config.username,
      pass: config.password,
    },
  });
...

This is how Wasp is currently "initializing smtp email sender". My thought was to add the field secure and requireTLS and allow the user to set said parameters through the .env.server like the host, port, username, and password.

By the way, the error I get is only occurring after deploying my app to Fly.io (using the CLI). When running my app locally AWS SES doesn't seem to have any problems. This the error from my live logs of my server:

2024-07-07T21:03:39.764 app[...] mia [info] Failed to send email Error: connect ECONNREFUSED 127.0.0.1:587

2024-07-07T21:03:39.764 app[...] mia [info] at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)

2024-07-07T21:03:39.764 app[...] mia [info] at __node_internal_exceptionWithHostPort (node:internal/errors:671:12)

2024-07-07T21:03:39.764 app[...] mia [info] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {

2024-07-07T21:03:39.764 app[...] mia [info] errno: -111,

2024-07-07T21:03:39.764 app[...] mia [info] code: 'ESOCKET',

2024-07-07T21:03:39.764 app[...] mia [info] syscall: 'connect',

2024-07-07T21:03:39.764 app[...] mia [info] address: '127.0.0.1',

2024-07-07T21:03:39.764 app[...] mia [info] port: 587,

2024-07-07T21:03:39.764 app[...] mia [info] command: 'CONN'

2024-07-07T21:03:39.764 app[...] mia [info] }
infomiho commented 3 weeks ago

Thank you for the report! This is really unfortunate, have you maybe found a way around it?

This is related to #1553 and we are looking to open up the customization of the email sender options.

nicolasf10 commented 3 weeks ago

@infomiho thanks for the reply! I haven't solved the issue yet, but the error I wrote earlier is gone after adding the SMTP variables (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD) directly in the fly-server.toml file. Now the issue seems to be related to the AWS SES credentials: Failed to send email Error: Missing credentials for "PLAIN"Failed to send email Error: Missing credentials for "PLAIN"

nicolasf10 commented 3 weeks ago

I managed to fix the issue! As you can see in the previous message I set the username variable name to SMTP_USER instead of SMTP_USERNAME. For some reason I had to declare these variables not only on the .env.server file, but also directly write them on the fly-server.toml and it worked!

fly-server.toml
[env]
  SMTP_HOST = "email-smtp.[region].amazonaws.com"
  SMTP_PORT = "..."
  SMTP_USERNAME = "..."
  SMTP_PASSWORD = "..."
infomiho commented 3 weeks ago

@nicolasf10 I'd advise against setting the env vars this way. The TOML file is meant to be included in your version control (e.g. Git) so it shouldn't contain secrets like this.

Setting the env vars in .env.server only works for you in the development, but in production you need to set env vars on the Fly dashboard or via the CLI. Here we wrote about dev/prod differences: https://wasp-lang.dev/docs/project/env-vars

nicolasf10 commented 3 weeks ago

Thank you for the heads up I now managed to set the variables through the Fly dashboard and it's working 🙏

Martinsos commented 2 weeks ago

Closing as it will be done as part of #1553 .