我们目前正在使用Nodemailer发送和接收公司内部的电子邮件。我们最近已经超过了我们的日常SMTP中继,这意味着一些电子邮件将不会发送。我被要求检查有多少电子邮件,我们的“无回复”电子邮件发送每天的基础上,看看是否有一个原因,我们正在超过这些限制。任何建议和想法将不胜感激。
注意:我是Nodemailer的新手,对它了解不多。
我试着破译现有的代码,但没有多大意义。我想我应该创建一个计数器,每当有来自该电子邮件的sendmail()请求时,该计数器就会递增,但我不知道如何发送说明该值的每日报告。
这是我们的server.js文件中的内容。注意:出于保密目的,已修改了一些名称
var smtpTransport = nodemailer.createTransport({
service: env.EMAIL.SERVICE,
host: env.EMAIL.HOST,
auth: {
user:env.EMAIL.AUTH.USER,
pass:env.EMAIL.AUTH.PASS
}
});
app.get('*', function (request, response) {
if (request.get('x-auth')) console.log("x-auth: ", request.get('xauth'));
const proto = request.get('X-Forwarded-Proto');
if (proto) {
if (proto === 'http') response.redirect(301,"https://myapplication.net".concat(request.url));
}
response.sendFile(path.resolve(__dirname, '../', 'public', 'index.html'))
if ((request.url).substring(0, 5) == "/send") {
var mailOptions = {
to: request.query.to,
bcc: request.query.bcc,
subject: request.query.subject,
text: request.query.text
}
//console.log(mailOptions); Read up on NodeMailer for details.
smtpTransport.sendMail({ //email options
from: " <noreply@someemail.com>", // sender address. Must be the same as authenticated user if using Gmail.
to: mailOptions.to,
bcc: " <noreply@someemail.com>",
subject: mailOptions.subject, // subject
html: mailOptions.text // body
}, function (error, response) { //callback
if (error) {
//console.log(error);
} else {
//console.log("Message sent: " + response.message);
}
smtpTransport.close(); // shut down the connection pool, no more messages. Comment this line out to continue sending emails.
});
}
});
我猜这就是它的名字
var to = this.props.msgList.EmailTo;
var text = `<div>Hello from no-reply</div>`;
$.get("/send", { to: to, subject: 'Response Rates', text: text },function (data) { });
package.json
{
"name": "my-app",
"version": "0.0.2",
"main": "index.js",
"author": "",
"license": "MIT",
"scripts": {
"start": "node src/entry",
"start-dev": "npm-run-all --parallel build babel-node",
"serve": "live-server public/",
"build-linux": "clear && webpack && clear && yarn build-server && clear && yarn start",
"build-windows": "cls && webpack && cls && yarn build-server && cls && yarn start",
"build-server": "babel src/server -d src",
"dev-server": "webpack-dev-server",
"babel-node": "nodemon --exec babel-node src/server.js"
},
"dependencies": {
"@babel/polyfill": "^7.0.0",
"axios": "^0.19.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "7.1.1",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "6.24.1",
"babel-preset-stage-0": "^6.24.1",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"core-js": "^2.5.3",
"css-loader": "0.28.4",
"express": "latest",
"file-loader": "^1.1.5",
"google-maps-react": "^2.0.2",
"image-webpack-loader": "^3.4.2",
"immutability-helper": "^2.4.0",
"jquery": "^3.4.1",
"jsonwebtoken": "^8.1.0",
"lodash": "^4.17.14",
"moment": "^2.22.2",
"node-sass": "^4.12.0",
"node-schedule": "^1.3.2",
"nodemailer": "^4.7.0",
"normalize.css": "7.0.0",
"npm": "^6.10.0",
"promise-mysql": "^3.1.0",
"prop-types": "^15.6.0",
"react": "^16.0.0",
"react-csv": "^1.0.14",
"react-dom": "^16.0.0",
"react-router-dom": "4.2.2",
"react-scripts": "1.0.14",
"sass-loader": "6.0.6",
"socket.io": "^2.0.3",
"style-loader": "0.18.2",
"twilio": "^3.24.0",
"validator": "8.0.0",
"webpack": "3.1.0",
"webpack-dev-server": "2.5.1"
},
"devDependencies": {
"concurrently": "^3.5.0",
"npm-run-all": "^4.1.1"
}
}
1条答案
按热度按时间cbeh67ev1#
您可以创建一个计数器,使用类似于node-scheduler https://www.npmjs.com/package/node-schedule(https://www.npmjs.com/package/node-schedule]) found here a这样的工具来设置每天重复发生的事件,该事件发送(通过电子邮件?记录到控制台?)计数器的值并在第二天重置该值。