在这个npm包的doc中: https://www.npmjs.com/package/express-mailer
Config必须位于app.js文件中:
// project/app.js
var app = require('express')(),
mailer = require('express-mailer');
mailer.extend(app, {
from: 'no-reply@example.com',
host: 'smtp.gmail.com', // hostname
secureConnection: true, // use SSL
port: 465, // port for secure SMTP
transportMethod: 'SMTP', // default is SMTP. Accepts anything that nodemailer accepts
auth: {
user: 'gmail.user@gmail.com',
pass: 'userpass'
}
});
但我有这个结构:
app_dir
config_dir
mail.js
app.js
需要将此块放在mail.js
中可以这样做吗?
由于
答案 0 :(得分:0)
使用js config(你想要的)
// project/config_dir/mail.js
module.exports = {
from: 'no-reply@example.com',
host: 'smtp.gmail.com', // hostname
secureConnection: true, // use SSL
port: 465, // port for secure SMTP
transportMethod: 'SMTP', // default is SMTP. Accepts anything that nodemailer accepts
auth: {
user: 'gmail.user@gmail.com',
pass: 'userpass'
}
}
// project/app.js
var app = require('express')(),
mail_config = require('./config_dir/mail');
mailer = require('express-mailer');
mailer.extend(app, mail_config);
使用json config
// project/config_dir/mail.json
{
from: "no-reply@example.com",
host: "smtp.gmail.com",
secureConnection: true,
port: 465,
transportMethod: "SMTP",
auth: {
user: "gmail.user@gmail.com",
pass: "userpass"
}
}
// project/app.js
var app = require('express')(),
mail_config = require('./config_dir/mail.json');
mailer = require('express-mailer');
mailer.extend(app, mail_config);