Email fails after deploy? Check your env variable names

Every key is set and the app still fails, because it reads MAIL_FROM while you set EMAIL_FROM. How to find the names your app reads and avoid silent fallbacks.

Simon, Founder of Shipyard

By · Founder of Shipyard

2 minute read

The short answer

An app reads its settings under the exact names written in its code. If you set the sender address as EMAIL_FROM and the code reads MAIL_FROM, the app sees nothing, quietly falls back to a default sender on a domain you do not own, and the email service refuses every message. The fix is to use the names listed in the repository's .env.example, or set both.

Why this happens more with AI-written code

Different coding tools, and the same tool on different days, pick different names for the same thing: MAIL_FROM, EMAIL_FROM, FROM_EMAIL, RESEND_FROM. Platforms and templates have their own conventions too. Nothing checks that the name you set on the host matches the name in the code.

Where to find the real names

How to spot it quickly

The symptom is a setup that looks complete: every key is on the host, the site loads, and still one feature fails without an error on screen. Open the host's logs and the email service's log first. If the email service shows rejected messages from an address on a domain you do not own, or shows nothing at all, the app is not reading the sender or the key you set. The same pattern holds for payments, where the webhook arrives but cannot be verified, and for sign-in links that point at a localhost address because the site URL was set under the wrong name.

The usual suspects

Setting both names is fine

It feels untidy to set the same value twice, under EMAIL_FROM and MAIL_FROM, but it costs nothing and removes a whole class of failure. Unused variables do no harm. What does harm is a variable the app needs that nobody set. If you want tidiness later, rename the variable in the code and in .env.example in one change, deploy, then delete the old name from the host.

Make failures loud

Ask your coding tool to check required variables when the app starts and stop with a clear message naming the missing one. A silent default, such as a sender on someone else's domain, is how a setup can look complete while nothing works.

How Shipyard avoids it

When Shipyard writes the variables for a launch, it reads the repository's .env.example first. If the app uses a different name for a value, it writes that name as well, and it lists the variables the file mentions that it could not fill, so you see them before you go live.

Launch in an hour, not a weekend

Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.

See how it works

Read next