Emailjs problems [Solved-ish]

Emailjs problems [Solved-ish]


Ok, last night I ran into issues with implementing emailjs in my voting app.

Has anybody used emailjs with Gmail, and are you aware of any obvious or non-obvious gotchas I may have missed?

I get authentication issues when I try to pass my email password as an environment variable, even though it works fine when I hard code it in.

Obviously I don’t want to hard code my email password into something that’s going on GitHub!

Anyone had and solved his problem?

Edit here’s the relevant emailjs config:

var yourEmail = '';
    var yourPwd = process.env.EMAIL_PASSWORD;
    var yourSmtp = '';
    var smtpServer  = email.server.connect({
      user:    yourEmail, 
      password: yourPwd, 
      host:    yourSmtp, 
      ssl:     true


Hi Jackson,

I don’t know if you solved this yet but have you tried using the dotenv package?


I hadn’t tried dotenv…I’ll try it later, thanks for the suggestion.


dotenv is definitely a nice package. Your code looks fine. Have you logged yourPwd? Any possibility it is not of type String?


I tried dotenv with EMAIL_PASSWORD and it still didn’t work, locally or via heroku. Also, heroku complains about not being able to find .env (is that because it’s in gitignore? How do you get around that?)

I also discovered that gmail doesn’t like you to use Heroku, I think.

My current solution is to use outlook and hardcode the password for a throwaway account.


Did you get the single use password for your application from Google? It will be necessary because Google doesn’t allow you to use your normal password for things like this.


I didn’t…a cursory glance at it reveals that my account is not set up for this kind of password. I’m sticking with Outlook for the moment. Thanks anyway :slight_smile:



I think dotenv is not designed to work with Heroku, since Heroku can store its own config vars anyway, and as I mentioned above, you shouldn’t be committing a .env to the git from which the Heroku app deploys.

So, I can use .env for local development, but have to remember to comment out its include when I push it to Heroku and let the Heroku config takeover.

I finally got the local env reading from dotenv, after changing the variable name again - maybe it was clashing with something, somehow…I can’t imagine how, but a clean attempt did the job.

Heroku is playing nicely with Outlook without me having to set up a special set of app keys.

It does seem to have one quirk. The response takes longer than the default timeout for emailjs (maybe to dissuade spam bots?), so I bumped the timeout up and it works now…you only have to wait 20 seconds…users on the modern internet are cool with that, right? :stuck_out_tongue_winking_eye:

Anyway - now my passwordless authentication is working I can actually build the rest of the app.

Thanks @mikethecodegeek, @BenGitter, @P1xt and @jondcoleman