Then everything would generally appear to be correct. How are you starting the iex session that is working? You could also verify with env | grep SENDGRID_API_KEY in the terminal before running iex -S mix phx.server.
If that doesn’t work then it will probably be necessary to look at the rest of your config.exs and config/dev.exs. Another debugging step would be to add IO.inspect(System.get_env()) right before you try to read the environment variable.
secret_key_base =
System.get_env("SECRET_KEY_BASE") ||
raise """
environment variable SECRET_KEY_BASE is missing.
You can generate one by calling: mix phx.gen.secret
"""
I tried IO.inspecting System.get_env/0 and that worked, but the environment variables are all different than what I am seeing in iex console. I am wondering if it has something to do with the new zsh console on mac. It looked to me like the things output in development were from my bash environment.
When I run iex -S mix phx.server 59 environment variables show (NOT including the one I want), but when I run iex -S mix only 39 show (including the one I want).
Solution
I took a gamble and just ran $ export SENDGRID_API_KEY='MY_API_KEY' again, now everything is working!
Not sure why it didn’t work the first time, oh well. My guess is quitting terminal and reloading it might have also fixed this.