5

I'm trying to get my hands dirty with Nodemailer and I am getting the above error message. If I set up my email address and password as plain text then the app works fine, obviously I would rather not do that as I will be pushing to Github, so I have set them up as environment variables as below, unfortunately this leads to the above error message.

I have set up my Gmail account to allow less secure apps.

I have also tried to create a secret.js file with the data in, imported it into app.js and added it to my .gitignore, the issue there is when I try to deploy to Heroku, I guess Heroku has to have access to that file to run the script so it crashes.

let transporter = nodemailer.createTransport({
    service: 'gmail',
    secure: false,
    port: 25, // true for 465, false for other ports
    auth: {
        user: process.env.EMAIL, // generated ethereal user
        pass: process.env.PASSWORD // generated ethereal password
    },
    tls: {
        rejectUnauthorized: false
    }
});

I have set my environment variables thusly and none of them work:-

set EMAIL=email@email.com
set EMAIL='email@email.com'
set EMAIL="email@email.com"

I've also used single quotes with ${} hoping this might help, but nope. Completely baffled.

Kieran
  • 51
  • 1
  • 3

3 Answers3

2

You need to add this require in email verification file

require("dotenv").config();
var transport = nodemailer.createTransport({
              service: "hotmail",
              auth: {
                      user: process.env.EMAIL_ID,
                       pass: process.env.PASS
                    });
Ricardo Gonzalez
  • 1,827
  • 1
  • 14
  • 25
ADITYA KUMAR
  • 21
  • 1
  • 6
1

It's not recognizing your env variables. Where is your server.js file located in relation to the env file? Put them in the same directory.

jrvscm
  • 11
  • 1
0

Let say you're about to upload a bundle to Firebase using their Cloud Functions for Firebase from function folder. Then you .env file has to be in the root of functions, in order not to return undefined.

Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94