我正在用NodeJS做电子邮件代码。我正在尝试从Laravel .env文件获取配置,但操作没有进行。我正在尝试这样:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.ionos.com
MAIL_PORT=587
MAIL_USERNAME=my_email
MAIL_PASSWORD=my_password
MAIL_ENCRYPTION=null
像这样访问它:
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
}
});
答案 0 :(得分:0)
我认为您应该使用dotenv包来导入Laravel .env变量,例如
require('dotenv').config({path: '/path/to/laravel/env/file/vars.env'})
然后您可以使用process.env.MAIL_USERNAME
或process.env.MAIL_PASSWORD