Emailjs problems [Solved-ish]

Emailjs problems [Solved-ish]
0

#1

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 = 'malgalin@gmail.com';
    var yourPwd = process.env.EMAIL_PASSWORD;
    var yourSmtp = 'smtp.gmail.com';
    var smtpServer  = email.server.connect({
      user:    yourEmail, 
      password: yourPwd, 
      host:    yourSmtp, 
      ssl:     true
    });

#2

Hi Jackson,

I don’t know if you solved this yet but have you tried using the dotenv package?
https://www.npmjs.com/package/dotenv


#3

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


#4

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


#6

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.


#7

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.


#8

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:


#9

So…

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