W
Wasp-lang4mo ago
mm

How: Dynamic Email Sender configuration

Is there a way to set the Email Sender config in main.wasp dynamically depending on environment? Would be great if we can import values from .env in main.wasp
8 Replies
kapa.ai
kapa.ai4mo ago
Hi @mm. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Currently, Wasp does not support dynamic variables in the main.wasp file, which includes dynamically setting the Email Sender configuration based on the environment. This is a feature that the Wasp community has expressed interest in and the Wasp team is considering for future implementation source (https://discord.com/channels/686873244791210014/1223180353460506695). However, there are some workarounds you can use in the meantime. For example, you can use different email providers for different environments by manually changing the provider field in the emailSender dict in your main.wasp file source (https://wasp-lang.dev/docs/advanced/email#emailsender-dict). For development, you can use the Dummy provider, which doesn't send emails but logs them to the console source (https://wasp-lang.dev/docs/advanced/email#using-the-dummy-provider). For production, you can use providers like SMTP, Mailgun, or SendGrid source (https://wasp-lang.dev/docs/advanced/email). Here's an example of how to set the Dummy provider:
app Example {
...
emailSender: {
provider: Dummy,
}
}
app Example {
...
emailSender: {
provider: Dummy,
}
}
And here's an example of how to set the SMTP provider:
app Example {
...
emailSender: {
provider: SMTP,
}
}
app Example {
...
emailSender: {
provider: SMTP,
}
}
You can set environment variables for these providers in the .env.server file source (https://wasp-lang.dev/docs/advanced/email#providers). Remember to change the provider field in your main.wasp file depending on the environment you're working in. This is not an ideal solution as it involves manual changes, but it's a workaround until Wasp supports dynamic variables in the main.wasp file. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @mm, 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?
martinsos
martinsos4mo ago
@mm not at the moment! It will be possible with the next TS SDK that we plan to release in the next quarter (main.wasp.ts). I am guessing you would like to use Dummy in development and Sengrid in production, something like that? If so, that is generally not recommended, as you would ideally do development with the exactly the same setup (or as close as possible) to production, to minimize unexpected mistakes / behaviour that you haven't detected during development. What was your motivation for this?
mm
mmOP4mo ago
I understand @martinsos Thank you. Well dummy is the fastest to check (console), but I agree with you it would be great to have the same setup for dev and prod. There's actually a better option where there's no need to change the config in main.wasp, by using Mailhog, https://github.com/mailhog/MailHog. This is great for local testing, maybe you can also add this as one of your recommendations in the docs Also there are times when we go to places where the internet is bad, or no internet at all, that's less likely to happen tho, and you can always swap the config if needed.
MEE6
MEE64mo ago
Wohooo @mm, you just became a Waspeteer level 3!
mm
mmOP4mo ago
I'm excited for the TS SDK, it will greatly help with the scalability of wasp. Well this is really not an important feature, having dynamic sender config. it's pretty dynamic using SMTP
martinsos
martinsos4mo ago
That is great to hear, we are also excited :D! Thanks for sharing MailHog that is interesting!
mm
mmOP4mo ago
hi @martinsos I created a dev article for this one https://dev.to/medardm/using-mailhog-in-wasp-4n2p This is actually my first lol, apologies if it's not that good, let me know if I need to change anything
DEV Community
🐝 ✉️ Using MailHog in Wasp
What is Wasp I'll assume you already know Wasp. For more information, please check their...
Filip
Filip4mo ago
@Vinny (@Wasp) You're the resident expert. Can you take a look?
Want results from more Discord servers?
Add your server