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:
Is this connecting to my own address on port 587? will opening this port help with smth or is it other problem?
8 Replies
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:
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):
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?@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
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
.
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?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.
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:
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
DataError: Zero-length key is notThat 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:
Then run your server app with: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?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!
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? 🙂