Get number of emails sent daily by "no-reply email" using Nodemailer - javascript

We are currently using Nodemailer to send and receive emails within our company. We recently have been exceeding our daily SMTP relays which means that some emails will not send. I was asked to check how many emails our "no-reply" email sends on a daily basis to see if there is a reason we are exceeding these limits. Any suggestions and ideas would be greatly appreciated.
NOTE: I'm new to Nodemailer and don't know much about it.
I've tried deciphering the existing code and can't make much sense out of it. I figured that I would just create a counter that would increment every time there is a sendmail() request from that email, but I don't know how to send a daily report that states what that value is.
This is what's in our server.js file
NOTE: Some names have been modified for confidential purposes
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.
});
}
});
I assume this is how it gets called
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"
}
}

You can create a counter as you stated an use something like node-scheduler [https://www.npmjs.com/package/node-schedule] found here to setup a recurring event on a daily basis that both sends (via email? logged to console?) the value of the counter and resets it for the next day.

Related

Cannot find module 'table-hints' when running a sequelize powered express app

I am having an issue with my ExpressJS app using sequelize. When I run the app, I get this message:
node:internal/modules/cjs/loader:488
throw e;
^
Error: Cannot find module
'C:\node_projects\my_app\node_modules\sequelize\dist\lib\table-hints'
This issue started happening after I edited one of my app's routes, which has nothing to do with app initialization. I cannot share code, because it seems to be a problem within sequelize itself.
My package.json looks like this:
{
"name": "my_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"client": "npm run start --prefix client",
"dexy": "concurrently \"npm start\" \"npm run client\" ",
"test": "node_modules/.bin/mocha tests.js --timeout 10000"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"bluebird": "^3.7.2",
"body-parser": "^1.19.1",
"cookie-session": "^2.0.0",
"ejs": "^3.1.6",
"express": "^4.17.2",
"express-validation": "^3.0.8",
"express-validator": "^6.14.0",
"helmet": "^4.6.0",
"joi": "^17.5.0",
"mailgun-js": "^0.22.0",
"moment": "^2.29.1",
"morgan": "^1.10.0",
"passport": "^0.5.2",
"passport-facebook": "^3.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"pg": "^8.7.1",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"sequelize": "^6.12.2",
"tedious": "^14.0.0",
"uuid": "^8.3.2"
}
}
The code I use to init my db is like this:
function dbInit(app){
const Sequelize = require('sequelize');
const keys = require('../config/keys');
const sqlCon = new Sequelize(keys.dbName,keys.dbUser, keys.dbPassword,
{dialect:'postgresql',
host:keys.dbHost,
pool:20,
logging:false
});
app.locals.connection = sqlCon;
//wire up model definitions
const User = require('../models/User')(sqlCon,sequelize);
const PasswordResetRequest = require('../models/PasswordResetRequest')(sqlCon,sequelize);
const CertType =require('../models/CertType')(sqlCon,sequelize);
const Role =require('../models/Role')(sqlCon,sequelize);
app.locals.User = User;
app.locals.PasswordResetRequest = PasswordResetRequest;
app.locals.CertType = CertType;
app.locals.Role = Role;
//setup relationships between tables
require('../models/relationships')(app);
sqlCon.sync().then(()=>{
return sqlCon.authenticate()
})
.catch((err)=>{
console.log('Successfully NOT connected to DB!');
console.log(err);
});
return sqlCon;
}
Can anyone shed any light on why this error happens? Thanks! I already downgraded sequelize from version 7-aplha2.

Keep getting Uncaught SyntaxError: cannot use import statement outside a module

I keep getting message even after trying out the following:
btw, I am using the exact same code as the lecture, so I'm guessing it might be a version issue.
1. Add "type":"module" in package.json file
//which throws a different error: [ERR_REQUIRE_ESM]: require() of ES Module not supported
2. use require() instead
// which throws another error: Uncaught ReferenceError: require is not defined
3. in html file, add type module
<script type = "module" src="./app/javascripts/app.js"></script>
app.js
// Import the page's CSS. Webpack will know what to do with it.
import "../stylesheets/app.css";
//Import libraries we need.
import { default as Web3} from 'web3';
import { default as contract } from 'truffle-contract';
import voting_artifacts from '../../build/contracts/Voting.json';
//require("../stylesheets/app.css")
//const Web3 = require("web3")
//const contract = require("truffle-contract")
//const voting_artifacts = require("../../build/contracts/Voting.json")
package.json
{
"name": "truffle-init-webpack",
"version": "0.0.1",
"description": "Frontend example using truffle v3",
"scripts": {
"build-amd": "npm run bundle-amd && npm run minify-amd",
"lint": "eslint ./",
"build": "webpack",
"dev": "webpack-dev-server"
},
"author": "Douglas von Kohorn",
"license": "MIT",
"devDependencies": {
"babel-cli": "^6.22.2",
"babel-core": "^6.22.1",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.10",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.1.8",
"babel-preset-es2015": "^6.22.0",
"babel-register": "^6.22.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.26.1",
"eslint": "^3.14.0",
"eslint-config-standard": "^6.0.0",
"eslint-plugin-babel": "^4.0.0",
"eslint-plugin-mocha": "^4.8.0",
"eslint-plugin-promise": "^3.0.0",
"eslint-plugin-standard": "^2.0.0",
"html-webpack-plugin": "^2.28.0",
"json-loader": "^0.5.4",
"style-loader": "^0.13.1",
"truffle-contract": "^1.1.6",
"web3": "^0.18.4",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.3.0"
},
"dependencies": {
"milsymbol": "^2.0.0",
"node-fetch": "^2.6.1",
"solc": "^0.8.10",
"truffle": "^4.0.1",
"truffle-hdwallet-provider": "latest"
}
}

Node js error require modules

I created an API including using of hummus.js. After testing it local, I uploaded my new API Build on my Server (Ubuntu Root + Plesk Onyx) and npm install my package.json (with Plesk => Output: Installation complete Status: Success). But my new Build doesn't work. After debugging my Code I detect the error. My API get an Internal Error after require one module (Tested this with that Code)
try {
var hummus = require('hummus');
var fillClass = require('../classes/fillform').fillForm;
}
catch (e) {
res.send("ERROR HUMMUS")
}
Run this Code I get = ERROR HUMMUS
I thought that the hummus path doesn't exist but with:
try {
res.send(require.resolve("hummus")).end();
} catch(e) {
res.send("not found").end();
process.exit(e.code);
}
I get the path to the module (hummus). Although all file in this folder exists.
(Other modules like async, fs etc works well)
What I do wrong? What should I do?
Greetings
edit Package.json
{"name": "XXX-API",
"version": "1.0.9",
"main": "server.js",
"dependencies": {
"archiver": "^2.0.0",
"array-sum": "^1.0.0",
"async": "^2.5.0",
"big-integer": "^1.6.24",
"body-parser": "^1.17.2",
"child_process": "^1.0.2",
"cors": "^2.8.3",
"curl": "^0.1.4",
"express": "^4.15.3",
"file-encryptor": "^0.1.1",
"fs": "0.0.1-security",
"ftp": "^0.3.10",
"ftp-client": "^0.2.2",
"ftps": "^1.1.0",
"german-tax-id-validator": "^1.0.3",
"https": "^1.0.0",
"hummus": "^1.0.80",
"ibantools": "^1.3.0",
"jsftp": "^2.0.0",
"leading-zeros": "^1.0.1",
"lodash": "^4.17.4",
"mysql": "^2.13.0",
"node-datetime": "^2.0.0",
"node-pdffiller": "0.0.7",
"node-uuid": "^1.4.8",
"node-zip": "^1.1.1",
"nodemailer": "^4.0.1",
"pad-right": "^0.2.2",
"pdfkit": "^0.8.3",
"phantomjs": "^2.1.7",
"pug": "^2.0.0-rc.2",
"request-promise": "^4.2.1",
"requestify": "^0.2.5",
"shortid": "^2.2.8",
"slack-node": "^0.1.8",
"uid": "0.0.2",
"xmlbuilder": "^9.0.4"
}
}
Pls write the error to log.
... catch (err){
logger.debug(err.stack)
}
No better way than error stack.

when i run enzyme example, i got "SyntaxError: /Users/a2014/Desktop/draghtml/test/test.js: Unexpected token (58:26)"

this is my test code
import React from 'react';
import { expect } from 'chai';
import { mount, shallow } from 'enzyme';
import Welcome from '../script/src/entry';
describe('<Welcome />', () => {
it('calls componentDidMount', () => {
const wrapper = mount(<Welcome />);
expect(Welcome.prototype.componentDidMount.calledOnce).to.equal(true);
});
});
this is my package.json
"scripts": {
"cover": "istanbul cover _mocha -- --delay",
"test": "mocha --compilers js:babel-core/register --require ./test/test.js",
"dev": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chai": "^4.1.1",
"enzyme": "^2.9.1",
"html-webpack-plugin": "^2.30.1",
"isparta-loader": "^2.0.0",
"istanbul": "^0.4.5",
"jsx-loader": "^0.13.2",
"karma": "^1.7.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-firefox-launcher": "^1.0.1",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.4",
"karma-spec-reporter": "0.0.31",
"karma-webpack": "^2.0.4",
"mocha": "^3.5.0",
"phantomjs-polyfill": "0.0.2",
"react-addons-test-utils": "^15.6.0",
"react-test-renderer": "^15.6.1",
"should": "^11.2.1",
"webpack": "^3.4.1"
},
"dependencies": {
"babel-runtime": "^6.25.0",
"react": "^15.6.1",
"react-dom": "^15.6.1"
}
when i run "npm run test",it got an error,how to solve it?
SyntaxError: /Users/a2014/Desktop/draghtml/test/test.js: Unexpected token (58:26)
58: const wrapper = mount(<Welcome />);
it seems like dont't resolve
You need to use Babel with a correct preset to parse the JSX syntax of your component, which is not supported by NodeJS, event in the latest version, and it will probably won't be supported in the future.
One option is to install the React preset and include it in a .babelrc file:
{
"presets": ["react"]
}

ReactNative: babelHelpers.typeof is not a function

On an existing project, that have worked fine over many months and which is already in the AppStores for both iOS and Android, we've got now a break on development with this error:
babelHelpers.typeof is not a function
All what we've done was to try to upgrade an RN-0.26-based Application to a newer version. But even after a rollback the error remains.
We cleared watchman, resetted the packager multiple times. Nothing helped here.
Our package.json looks like this:
{
"version": "0.0.1",
"private": true,
"scripts": {
"reset": "rm -rf node_modules/ && npm cache clear && watchman watch-del-all && npm i",
"start": "node node_modules/react-native/local-cli/cli.js start --reset-cache",
"testflight": "fastlane beta",
"android-device": "adb reverse tcp:8081 tcp:8081 && react-native run-android",
"lint": "jslint **.js",
"test": "mocha test/",
"generate-apk": "cd android && ./gradlew assembleRelease && open ./app/build/outputs/apk/",
"install-apk": "cd android && ./gradlew installRelease",
},
"devDependencies": {
"jshint": "latest",
"mocha": "latest",
"eslint": "^2.3.0",
"eslint-config-standard": "^5.1.0",
"eslint-config-standard-react": "^2.3.0",
"eslint-plugin-promise": "^1.1.0",
"eslint-plugin-react": "^4.1.0",
"eslint-plugin-react-native": "^1.0.0",
"eslint-plugin-standard": "^1.3.2"
},
"dependencies": {
"apsl-react-native-button": "^2.5.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"es6-promisify": "^4.1.0",
"fetch-stuff": "^1.0.1",
"iap-receipt-validator": "^1.0.2",
"immutable": "^3.8.1",
"js-sha256": "^0.3.0",
"keymirror": "^0.1.1",
"lodash.difference": "^4.3.0",
"lodash.find": "^4.4.0",
"lodash.partialright": "^4.1.4",
"lodash.remove": "^4.5.0",
"lodash.shuffle": "^4.0.0",
"lodash.uniq": "^4.3.0",
"moment": "^2.14.1",
"normalizr": "^2.1.0",
"react": "15.0.2",
"react-native": "0.26.2",
"react-native-animatable": "^0.6.1",
"react-native-app-intro": "^1.0.2",
"react-native-billing": "^1.3.0",
"react-native-code-push": "^1.12.2-beta",
"react-native-code-push-saga": "^1.0.0",
"react-native-console-panel": "0.0.9",
"react-native-debug-stylesheet": "^0.1.1",
"react-native-drawer": "file:./custom_modules/react-native-drawer",
"react-native-extra-dimensions-android": "^0.17.0",
"react-native-fabric": "^0.2.3",
"react-native-fetch-blob": "^0.4.2",
"react-native-fs": "^1.4.0",
"react-native-gifted-spinner": "0.0.4",
"react-native-google-analytics-bridge": "^2.1.0",
"react-native-htmlview": "^0.5.0",
"react-native-i18n": "0.0.8",
"react-native-image-progress": "^0.5.0",
"react-native-in-app-utils": "^4.0.0",
"react-native-keyboard-aware-scroll-view": "^0.1.0",
"react-native-navbar": "^1.5.0",
"react-native-router-flux": "^3.30.0",
"react-native-search-bar": "^2.11.0",
"react-native-side-menu": "^0.19.0",
"react-native-simple-store": "^1.0.1",
"react-native-sound": "^0.8.3",
"react-native-sqlite-storage": "^2.1.6",
"react-native-swiper": "^1.4.4",
"react-native-vector-icons": "^2.0.2",
"react-redux": "^4.4.5",
"react-timer-mixin": "^0.13.3",
"redux": "^3.5.2",
"redux-form": "^6.0.0-alpha.15",
"redux-logger": "^2.6.1",
"redux-saga": "^0.10.4",
"redux-thunk": "^2.1.0",
"reselect": "^2.5.1",
"rn-viewpager": "^1.1.2",
"rnpm": "^1.7.0",
"tween-functions": "^1.2.0"
}
}
Can anyone help?
The issue happens because either your project (via a custom .babelrc) or one of your dependencies is relying on a es2015 preset that doesn't work with React Native. The reason for that is because it includes transform-typeof-symbol which calls babelHelpers.typeof that is not bundled with React Native.
If you have a custom babelrc - the solution is simple, just remove this preset.
Afterwards, restart packager w/o cache and you should be set.
Note: It maybe one of your dependencies that uses that preset - in such case, there's nothing you can do but try forking it and removing the preset yourself.
A part solution to this is using babel-preset-react-native-stage-0
https://www.npmjs.com/package/babel-preset-react-native-stage-0
There is a PR here to fix this in the react-native codebase: enter link description here

Categories