W
Wasp-lang•4w ago
varo

SMTP on wasp build connecting on localhost instead of my SMTP provider

So basically, I have my SMTP configured to be on SMTP2go, with the hosting and password as env variables, also in main.wasp it is set to SMTP. When I try on dev mode (with wasp start) it connects to the SMTP host and sends the email correctly, but when I build all the stuff and deploy both backend and frontend, when it comes to sending a mail, it shows this:
POST /auth/email/signup 200 44.671 ms - 16
Failed to send email Error: connect ECONNREFUSED 127.0.0.1:587
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:671:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -111,
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 587,
command: 'CONN'
}
POST /auth/email/signup 200 44.671 ms - 16
Failed to send email Error: connect ECONNREFUSED 127.0.0.1:587
at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
at __node_internal_exceptionWithHostPort (node:internal/errors:671:12)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
errno: -111,
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 587,
command: 'CONN'
}
Is this connecting to my own address on port 587? will opening this port help with smth or is it other problem?
8 Replies
kapa.ai
kapa.ai•4w ago
Hi @varo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in your question and the knowledge sources available, it appears that you're encountering an issue with SMTP configuration when deploying your Wasp application. Let me address your concerns: 1. The error message you're seeing suggests that the application is indeed trying to connect to 127.0.0.1 (localhost) on port 587, rather than your configured SMTP2go provider. This is not the expected behavior when you've set up an external SMTP provider. 2. Opening port 587 on your local machine won't help in this case, as the application should be connecting to the external SMTP server, not localhost. The discrepancy between the behavior in development mode and after deployment suggests that there might be an issue with how the environment variables are being set or read in the production environment. Here are a few things you can check: 1. Ensure that you've correctly set up the SMTP provider in your main.wasp file:
app Example {
...
emailSender: {
provider: SMTP,
}
}
app Example {
...
emailSender: {
provider: SMTP,
}
}
2. Verify that you've set the correct environment variables in your .env.server file as mentioned in the Wasp documentation on SMTP provider (https://wasp-lang.dev/docs/advanced/email#using-the-smtp-provider):
SMTP_HOST=
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_PORT=
SMTP_HOST=
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_PORT=
3. Make sure these environment variables are properly set in your production environment where you've deployed the application. 4. Double-check that the SMTP configuration is being correctly read in your production environment. The fact that it works in development but not in production suggests that there might be an issue with how the environment variables are being loaded or accessed after deployment. If you've verified all of these points and the issue persists, it might be worth creating an issue on the Wasp GitHub repository (https://github.com/wasp-lang/wasp) to get more specific help from the Wasp team. There's also an ongoing discussion about a similar issue in the Wasp community. As mentioned in this Discord thread (https://discord.com/channels/686873244791210014/1179895919471247490), changing the connection string from localhost to 127.0.0.1 might not be the best solution, as it could make the setup less future-proof. The Wasp team is investigating this behavior to see if it's related to a Node.js quirk on certain operating systems. If you continue to face this issue, consider reaching out to the Wasp community on their Discord channel or GitHub for more tailored assistance with your specific deployment setup. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @varo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
varo
varoOP•4w ago
@kapa.ai how can I check if my env variables are correcly set up? I can see other queries as get auth/me on the backend, so it at least connects each other
kapa.ai
kapa.ai•4w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To check if your environment variables are correctly set up, you can use the following steps: 1. Check the .env.server file: This file should contain your SMTP configuration. Make sure it has the correct values for SMTP_HOST, SMTP_USERNAME, SMTP_PASSWORD, and SMTP_PORT.
SMTP_HOST=your_smtp_host
SMTP_USERNAME=your_smtp_username
SMTP_PASSWORD=your_smtp_password
SMTP_PORT=your_smtp_port
SMTP_HOST=your_smtp_host
SMTP_USERNAME=your_smtp_username
SMTP_PASSWORD=your_smtp_password
SMTP_PORT=your_smtp_port
2. Check the environment variables in your production environment: The way to do this depends on where and how you've deployed your application. If you're using a platform like Heroku, you can check the environment variables in the settings of your application dashboard. If you're using a virtual private server, you can check the environment variables by running printenv in the terminal or looking at the /etc/environment file. 3. Check the environment variables in your application code: You can add some temporary debug logging to your application code to print out the values of the environment variables. For example, in Node.js, you can use console.log(process.env.SMTP_HOST) to print the value of SMTP_HOST. Make sure to remove these debug logs once you've finished troubleshooting. Remember, never share or expose your sensitive environment variables (like your SMTP password) in any public or insecure context. If you've checked all these places and your environment variables are correctly set up, but you're still having issues, it might be a problem with the application code or the SMTP provider. In that case, you might want to reach out to the Wasp community or your SMTP provider's support for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @varo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho•4w ago
We wrote about differences between dev and production env variables here: https://wasp-lang.dev/docs/project/env-vars Checking the production env variables will depend on your deployment method.
Env Variables | Wasp
Environment variables are used to configure projects based on the context in which they run. This allows them to exhibit different behaviors in different environments, such as development, staging, or production.
varo
varoOP•4w ago
Thanks for the response! I'm on ubuntu server with an VPS, and I've got my env variables available when I do printenv. And it stills sends to the localhost. I tried to force the variables passing them when running the docker, and it now shows:
POST /auth/email/signup 500 51.055 ms - 148
DataError: Zero-length key is not supported
at new DOMException (node:internal/per_context/domexception:53:5)
at __node_internal_ (node:internal/util:520:10)
at Object.hmacImportKey (node:internal/crypto/mac:103:15)
at SubtleCrypto.importKey (node:internal/crypto/webcrypto:631:10)
at HMAC.sign (file:///app/node_modules/oslo/dist/crypto/hmac.js:14:47)
at Module.createJWT (file:///app/node_modules/oslo/dist/jwt/index.js:42:53)
at createJWT (/app/.wasp/out/sdk/wasp/auth/jwt.ts:12:14)
at createEmailJWT (/app/.wasp/out/sdk/wasp/server/auth/email/utils.ts:33:26)
at createEmailVerificationLink (/app/.wasp/out/sdk/wasp/server/auth/email/utils.ts:19:30)
at signup (/app/.wasp/build/server/src/auth/providers/email/signup.ts:140:36)
POST /auth/email/signup 500 51.055 ms - 148
DataError: Zero-length key is not supported
at new DOMException (node:internal/per_context/domexception:53:5)
at __node_internal_ (node:internal/util:520:10)
at Object.hmacImportKey (node:internal/crypto/mac:103:15)
at SubtleCrypto.importKey (node:internal/crypto/webcrypto:631:10)
at HMAC.sign (file:///app/node_modules/oslo/dist/crypto/hmac.js:14:47)
at Module.createJWT (file:///app/node_modules/oslo/dist/jwt/index.js:42:53)
at createJWT (/app/.wasp/out/sdk/wasp/auth/jwt.ts:12:14)
at createEmailJWT (/app/.wasp/out/sdk/wasp/server/auth/email/utils.ts:33:26)
at createEmailVerificationLink (/app/.wasp/out/sdk/wasp/server/auth/email/utils.ts:19:30)
at signup (/app/.wasp/build/server/src/auth/providers/email/signup.ts:140:36)
I don't know if I didn't set up correctly, and if there isn't a way to check them instead of printenv (they appear on printenv) what I did with the docker was: ` docker run -d \ --name my-name \ --network wasp-network \ -p "8000:8000" \ -e DATABASE_URL="${DATABASE_URL}" \ -e PORT="8000" \ -e NODE_ENV="production" \ -e JWT_SECRET="${JWT_SECRET}" \ -e WASP_WEB_CLIENT_URL="${WASP_WEB_CLIENT_URL}" \ -e WASP_SERVER_URL="${WASP_SERVER_URL}" \ -e SMTP_HOST="${SMTP_HOST}" \ -e SMTP_USERNAME="${SMTP_USERNAME}" \ -e SMTP_PASSWORD="${SMTP_PASSWORD}" \ -e SMTP_PORT="${SMTP_PORT}" \ my-name
miho
miho•4w ago
DataError: Zero-length key is not
That sounds like a JWT_SECRET related error i.e. JWT_SECRET is not set. I did this in the VPS example https://gist.github.com/infomiho/80f3f50346566e39db56c5e57fefa1fe:
Go to the project dir (not .wasp/build) and create a .env.production file there with the following:
PORT=3001
DATABASE_URL=postgresql://postgres:mysecretpassword@db:5432/postgres
WASP_WEB_CLIENT_URL=https://myapp.com
WASP_SERVER_URL=https://api.myapp.com
# Generate the JWT secret with https://djecrety.ir/
JWT_SECRET=<some-random-string>
# Add any other env vars you need for your server e.g. GOOGLE_CLIENT_ID and similar.
PORT=3001
DATABASE_URL=postgresql://postgres:mysecretpassword@db:5432/postgres
WASP_WEB_CLIENT_URL=https://myapp.com
WASP_SERVER_URL=https://api.myapp.com
# Generate the JWT secret with https://djecrety.ir/
JWT_SECRET=<some-random-string>
# Add any other env vars you need for your server e.g. GOOGLE_CLIENT_ID and similar.
Then run your server app with:
docker run -d \
--name wasp-vps-app \
--env-file .env.production \
-p 127.0.0.1:3001:3001 \
--network wasp-vps-network \
wasp-vps-app
docker run -d \
--name wasp-vps-app \
--env-file .env.production \
-p 127.0.0.1:3001:3001 \
--network wasp-vps-network \
wasp-vps-app
I used an env file - but it's the same thing as passing the env vars directly. Have tried hardcoding the values -e SMRT_HOST=https://something.com to check that this is not the problem?
varo
varoOP•4w ago
thank you so much for the answer, I'll try it asap. also I will rebuild, just in case 🙂 It got solved, thanks! It didn't find exactly the .env.production as it was on the project root and I was throwing the docker command on .wasp/build, but rebuilding with some changes I took from the gist u shared made it work! It sure was my fault while managing the env variables. Thanks again!
miho
miho•4w ago
Thank you for reporting back 🙂 Is there anything we could maybe add to the gist as a warning for others? Something that could have helped you in this situation? 🙂
Want results from more Discord servers?
Add your server