使用 Nodemailer 获取 "no-reply email" 每天发送的电子邮件数量
Get number of emails sent daily by "no-reply email" using Nodemailer
我们目前正在使用 Nodemailer 在公司内部发送和接收电子邮件。我们最近一直在超过我们每天的 SMTP 中继,这意味着一些电子邮件不会发送。我被要求检查我们的 "no-reply" 电子邮件每天发送多少封电子邮件,看看我们是否有超出这些限制的原因。任何建议和想法将不胜感激。
注意:我是 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"
}
}
您可以创建一个计数器,正如您所说的那样,使用像节点调度程序 [https://www.npmjs.com/package/node-schedule] 在这里找到的东西来设置一个每天都发送(通过电子邮件?记录到控制台?)计数器的值并在第二天重置它。
我们目前正在使用 Nodemailer 在公司内部发送和接收电子邮件。我们最近一直在超过我们每天的 SMTP 中继,这意味着一些电子邮件不会发送。我被要求检查我们的 "no-reply" 电子邮件每天发送多少封电子邮件,看看我们是否有超出这些限制的原因。任何建议和想法将不胜感激。
注意:我是 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"
}
}
您可以创建一个计数器,正如您所说的那样,使用像节点调度程序 [https://www.npmjs.com/package/node-schedule] 在这里找到的东西来设置一个每天都发送(通过电子邮件?记录到控制台?)计数器的值并在第二天重置它。