Next.js Discord

Discord Forum

Nodemailer sends emails on development but not in production

Answered
Ashy Storm-Petrel posted this in #help-forum
Open in Discord
Avatar
Ashy Storm-PetrelOP
i've upload to vercel and this is insane why such a thing happens only in production
Answered by SupremeDeity
Try:
export const dynamic = 'force-dynamic'

In the route handler
View full answer

20 Replies

Avatar
Ashy Storm-PetrelOP
turn out nextjs is just caching first request and not sending new one
Avatar
dumbboy
the new cache system is frustating
Avatar
Ashy Storm-PetrelOP
can i disable it on my api routes?
i tried to do fetch no store in the frontend but that didn't fix it
Avatar
dumbboy
Honestly I don't know too
Avatar
SupremeDeity
Try:
export const dynamic = 'force-dynamic'

In the route handler
Answer
Avatar
Ashy Storm-PetrelOP
Thank you that's half the answer
The answer was that

first add
export const dynamic = 'force-dynamic'


then the response had to be dynamic because my response was
{Success: true}


so i had to put something changing so it ended up doing
{Success: `true ${Math.random()}`


not the best approach but worked
Avatar
dumbboy
so, it worked, can you mark this post as solved?
Avatar
Ashy Storm-PetrelOP
how can i do that?
Image
Avatar
dumbboy
Select the message that helped you solve this, apps -> mark as solution
^
Avatar
Transvaal lion
Can you please explain you solution a bit more like, where did you do
{Success: `true ${Math.random()}
Avatar
Ashy Storm-PetrelOP
On every response that nextjs sends so every request made will always make new response and not cache the data
Success true is just my message to tell the frontend that the mail is sent
Avatar
Transvaal lion
I have tried this but not working for me. I am using brevo SMTP for sending mail to users which do not have their password set yet... It is working fine on local but on production it is not working... Also please do let me know if there is any way you know for debugging production code?
Avatar
Ashy Storm-PetrelOP
tbh for me i just kept pushing my changes wait for building and test

what i did is i made a test endpoint which will send email as soon as i get to it and the response would be the results of the endpoints to see the message ID (will be new each time you sent email)