我正在尝试在 expressjs 应用程序中使用nodemailer。我应该继续在路由处理程序之外创建传输对象还是在路由处理程序中创建传输对象就可以了?
var express = require('express')
, app = express()
, nodemailer = require('nodemailer');
smtpTrans = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
user: "me@gmail.com",
pass: "application-specific-password"
}
});
app.post('/register', function(req, res){
smtpTrans.sendMail(mailOptions);
});
或者
var express = require('express')
, app = express()
, nodemailer = require('nodemailer');
app.post('/register', function(req, res){
smtpTrans = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
user: "me@gmail.com",
pass: "application-specific-password"
}
});
smtpTrans.sendMail(mailOptions);
});