2

I am doing email code in NodeJS. I am trying to get configurations from Laravel .env file it's not going on. I am trying like this:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.ionos.com
MAIL_PORT=587
MAIL_USERNAME=my_email
MAIL_PASSWORD=my_password
MAIL_ENCRYPTION=null

And accesing it like this:

let transporter = nodemailer.createTransport({
    host: process.env.MAIL_HOST,
    port: process.env.MAIL_PORT,
    secure: false, // true for 465, false for other ports
    auth: {
        user: process.env.MAIL_USERNAME, // generated ethereal user
        pass: process.env.MAIL_PASSWORD // generated ethereal password
    }
});
Kamal Paliwal
  • 1,251
  • 8
  • 16

1 Answers1

0

I think you should use dotenv package to import your Laravel .env variables, somthing like

require('dotenv').config({path: '/path/to/laravel/env/file/vars.env'})

then you can use process.env.MAIL_USERNAME or process.env.MAIL_PASSWORD

Milad Aghamohammadi
  • 1,866
  • 1
  • 16
  • 29