Using emailjs to send emails on my nodejs application.
However, it shows the error below when deployed on heroku, it's strange because application works locally
2018-01-28T22:28:24.689274+00:00 app[web.1]: { Error:
authorization.failed (timedout while connecting to smtp server)
2018-01-28T22:28:24.689286+00:00 app[web.1]: at module.exports
(/app/node_modules/emailjs/smtp/error.js:2:13)
2018-01-28T22:28:24.689290+00:00 app[web.1]: at failed
(/app/node_modules/emailjs/smtp/smtp.js:501:28)
2018-01-28T22:28:24.689292+00:00 app[web.1]: at response
(/app/node_modules/emailjs/smtp/smtp.js:506:13)
2018-01-28T22:28:24.689293+00:00 app[web.1]: at caller
(/app/node_modules/emailjs/smtp/smtp.js:48:14)
2018-01-28T22:28:24.689295+00:00 app[web.1]: at response
(/app/node_modules/emailjs/smtp/smtp.js:198:9)
2018-01-28T22:28:24.689296+00:00 app[web.1]: at caller
(/app/node_modules/emailjs/smtp/smtp.js:48:14)
2018-01-28T22:28:24.689298+00:00 app[web.1]: at TLSSocket.response
(/app/node_modules/emailjs/smtp/smtp.js:178:11)
2018-01-28T22:28:24.689300+00:00 app[web.1]: at Object.onceWrapper
(events.js:315:30)
2018-01-28T22:28:24.689302+00:00 app[web.1]: at emitOne
(events.js:116:13)
2018-01-28T22:28:24.689304+00:00 app[web.1]: at TLSSocket.emit
(events.js:211:7)
2018-01-28T22:28:24.689307+00:00 app[web.1]: code: 3,
2018-01-28T22:28:24.689308+00:00 app[web.1]: previous: { Error:
timedout while connecting to smtp server
2018-01-28T22:28:24.689310+00:00 app[web.1]: at module.exports
(/app/node_modules/emailjs/smtp/error.js:2:13)
2018-01-28T22:28:24.689312+00:00 app[web.1]: at TLSSocket.timedout
(/app/node_modules/emailjs/smtp/response.js:32:29)
2018-01-28T22:28:24.689313+00:00 app[web.1]: at Object.onceWrapper
(events.js:313:30)
2018-01-28T22:28:24.689314+00:00 app[web.1]: at emitNone
(events.js:106:13)
2018-01-28T22:28:24.689315+00:00 app[web.1]: at TLSSocket.emit
(events.js:208:7)
2018-01-28T22:28:24.689316+00:00 app[web.1]: at
TLSSocket.Socket._onTimeout (net.js:407:8)
2018-01-28T22:28:24.689318+00:00 app[web.1]: at ontimeout
(timers.js:475:11)
2018-01-28T22:28:24.689319+00:00 app[web.1]: at tryOnTimeout
(timers.js:310:5)
2018-01-28T22:28:24.689320+00:00 app[web.1]: at Timer.listOnTimeout
(timers.js:270:5) code: 4, smtp: undefined },
2018-01-28T22:28:24.689322+00:00 app[web.1]: smtp: undefined }
My code for stmp authentication
var server = email.server.connect({
user: email,
password: pass,
host: "smtp-mail.outlook.com",
tls: { ciphers: "SSLv3" }
});
I already tried
var https = require('https');
https.globalAgent.options.secureProtocol = 'SSLv3_method';
There's existing post for the similar problem, however, in this scenario i'm using outlook as opposed to other servcies
Related
I am using request to access data from an api. sometimes, when the api Url is down, node throws error and shuts down with the following error
`at ClientRequest.emit (events.js:315:20)`
`at TLSSocket.socketErrorListener (_http_client.js:426:9)`
`at TLSSocket.emit (events.js:315:20)`
`at emitErrorNT (internal/streams/destroy.js:92:8)`
`at processTicksAndRejections (internal/process/task_queues.js:84:21)
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: APIURL
is there any way to handle this and prevent node from exiting?
my code is
const JSONdata= ()=>{
request({url:API_URL2,json:true},(error,response,body)=>{
const data=[]
var jsondata=body
data.push(jsondata)
const data2=JSON.stringify(data)
fs.writeFile('sample.txt',data2,(err) => { if(error){console.log(error} })})
having a try-catch will prevent failure or system crash, also you get process.uncaughtException() to do something when the system crashes
check below link for more details
https://nodejs.org/api/process.html#process_event_uncaughtexception
I have a Heroku API written in JavaScript that reads data from a MySQL database. It previously worked, but now every time I send a request to the API, I get this error:
2020-06-17T18:37:13.493711+00:00 app[web.1]: > my_api#0.0.0 start /app
2020-06-17T18:37:13.493712+00:00 app[web.1]: > node ./bin/www
2020-06-17T18:37:13.493712+00:00 app[web.1]:
2020-06-17T18:37:14.977800+00:00 heroku[web.1]: State changed from starting to up
2020-06-17T18:38:40.255982+00:00 app[web.1]: /app/node_modules/mysql2/lib/connection.js:149
2020-06-17T18:38:40.256022+00:00 app[web.1]: err.fatal = true;
2020-06-17T18:38:40.256023+00:00 app[web.1]: ^
2020-06-17T18:38:40.256023+00:00 app[web.1]:
2020-06-17T18:38:40.256026+00:00 app[web.1]: TypeError: Cannot create property 'fatal' on string 'SOCKS: Authentication failed'
2020-06-17T18:38:40.256027+00:00 app[web.1]: at Connection._handleFatalError (/app/node_modules/mysql2/lib/connection.js:149:15)
2020-06-17T18:38:40.256027+00:00 app[web.1]: at Connection._handleNetworkError (/app/node_modules/mysql2/lib/connection.js:169:10)
2020-06-17T18:38:40.256027+00:00 app[web.1]: at SocksConnection.emit (events.js:315:20)
2020-06-17T18:38:40.256029+00:00 app[web.1]: at /app/node_modules/socksjs/socks.js:146:18
2020-06-17T18:38:40.256029+00:00 app[web.1]: at Socket.dataReady (/app/node_modules/socksjs/socks.js:93:13)
2020-06-17T18:38:40.256029+00:00 app[web.1]: at Socket.emit (events.js:315:20)
2020-06-17T18:38:40.256030+00:00 app[web.1]: at emitReadable_ (_stream_readable.js:556:12)
2020-06-17T18:38:40.256030+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:83:21)
2020-06-17T18:38:40.263200+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2020-06-17T18:38:40.263391+00:00 app[web.1]: npm ERR! errno 1
2020-06-17T18:38:40.264251+00:00 app[web.1]: npm ERR! my_api#0.0.0 start: `node ./bin/www`
2020-06-17T18:38:40.264354+00:00 app[web.1]: npm ERR! Exit status 1
2020-06-17T18:38:40.264471+00:00 app[web.1]: npm ERR!
The code in question looks like this:
function new_db_connection() {
var sockConn = new SocksConnection(remote_options, sock_options);
var dbConnection = mysql.createConnection({
user: 'myusername',
database: 'mydatabase',
password: 'mypassword',
stream: sockConn
});
return [sockConn, dbConnection];
};
router.get('/myrequest', function(req, res, next) {
new_conn = new_db_connection();
dbConnection = new_conn[1];
sockConn = new_conn[0];
dbConnection.query('SELECT * from mytable', function(error, results, fields) {
if (error) {
res.send(JSON.stringify({
"status": 500,
"error": error,
"response": null
}));
//If there is error, we send the error in the error section with 500 status
} else {
res.send(JSON.stringify({
"status": 200,
"error": null,
"response": results
}));
//If there is no error, all is good and response is 200OK.
}
sockConn.dispose();
});
dbConnection.end()
});
I saw a similar question asked on here and the solution was to close the connection, but I do close the connection after each request, so I don't know where the issue is.
All help appreciated.
Try to change this
sockConn.dispose();
});
dbConnection.end()
});
in this
sockConn.dispose();
dbConnection.end()
});
});
Edit: reading better the error, it could be the problem is some where else.
Looking at the string 'SOCKS: Authentication failed', could it be that you or the SocksConnection remote endpoint changed something in the authentication?
Hope this helps.
You should take a look at the answer provided by #daniele Rici you need to end your connection properly; however, fixing this will not solve your initial question.
The issue is not with your code. Your issue is with connection configuration.
'fatal' on string 'SOCKS: Authentication failed'
Means there was an error with authentication.
var sockConn = new SocksConnection(remote_options, sock_options);
under the assumention you are using ther npm package socksjs from https://openbase.io/js/socksjs
It is documented that the correct way to initialize a sockjs connection is by doing the following:
var sock = new SocksConnection(remote_options, sock_options);
var sock = SocksConnection.connect(remote_options, sock_options, connect_handler);
I did not have a problem connecting to Atlas previously from my wifi at home. But I have issues at Starbucks. I have now switched to google fiber and I am getting this error.
at Pool.<anonymous> (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/topologies/server.js:431:11)
at Pool.emit (events.js:182:13)
at connect (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/pool.js:557:14)
at callback (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/connect.js:109:5)
at runCommand (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/connect.js:129:7)
at Connection.errorHandler (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/connect.js:321:5)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at TLSSocket.<anonymous> (/Users/j/Desktop/projects/templateApp/node_modules/mongodb-core/lib/connection/connection.js:350:12)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at _handle.close (net.js:596:12)
at TCP.done [as _onclose] (_tls_wrap.js:383:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],```
I have checked my strings and they are correct.
My connection code is:
```mongoose.connect(process.env.dataBaseConnection, {
dbName: process.env.dataBaseName,
useFindAndModify: false,
useNewUrlParser: true
});```
The issue was that I needed to white list my new ip address.
im using heroku to host my site however it keeps spitting out the same error which is
2018-05-06T19:28:52.212104+00:00 app[web.1]:AssertionError [ERR_ASSERTION]: false == true
2018-05-06T19:28:52.212106+00:00 app[web.1]:at Object.exports.connect (_tls_wrap.js:1036:3)
2018-05-06T19:28:52.212107+00:00 app[web.1]: at Socket. (/app/node_modules/pg/lib/connection.js:94:23)
2018-05-06T19:28:52.212109+00:00 app[web.1]:at Object.onceWrapper (events.js:315:30)
2018-05-06T19:28:52.212110+00:00 app[web.1]:at emitOne (events.js:116:13)
2018-05-06T19:28:52.212112+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-05-06T19:28:52.212113+00:00 app[web.1]:at addChunk (_stream_readable.js:263:12)
2018-05-06T19:28:52.212115+00:00 app[web.1]:at readableAddChunk (_stream_readable.js:250:11)
2018-05-06T19:28:52.212116+00:00 app[web.1]:at Socket.Readable.push (_stream_readable.js:208:10)
2018-05-06T19:28:52.212118+00:00 app[web.1]: at TCP.onread >>(net.js:607:20)
this is how im connecting (taken straight off of herokus website)
const { Client } = require("pg");
const router = express.Router();
const pool = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
pool.connect();
I found out what the error was:
the error was that i did not have a db create. i decided to use elephantSQL and from their i connected to elephantSQL with pgadmin and recreated my database. it works perfect now
to see how this works see : https://www.elephantsql.com/docs/pgadmin.html
im more than happy to answer some questions
OK, this isn't really a solution but it might help you out. This happens to me on node 8 (and 10) but when I downgraded to node 7 it seems to work fine. I'll be watching this post to see if someone comes up with a better fix.
I have a Node.js app to do some simple processing, however, every time there's an error, the server crashes.
2011-12-19T19:27:49+00:00 app[web.1]: node.js:134
2011-12-19T19:27:49+00:00 app[web.1]: throw e; // process.nextTick error, or 'error' event on first tick
2011-12-19T19:27:49+00:00 app[web.1]: ^
2011-12-19T19:27:49+00:00 app[web.1]: TypeError: Object { customer_id: 4eef8ddb74019b9d4f00001d,
2011-12-19T19:27:49+00:00 app[web.1]: date: Mon, 19 Dec 2011 19:27:36 GMT,
2011-12-19T19:27:49+00:00 app[web.1]: callsid: '123',
2011-12-19T19:27:49+00:00 app[web.1]: _id: 4eef902887e9770100000008 } has no method 'save'
2011-12-19T19:27:49+00:00 app[web.1]: at Promise.<anonymous> (/app/src/call.js:137:24)
2011-12-19T19:27:49+00:00 app[web.1]: at Promise.<anonymous> (/app/node_modules/mongoose/lib/promise.js:120:8)
2011-12-19T19:27:49+00:00 app[web.1]: at Promise.<anonymous> (events.js:64:17)
2011-12-19T19:27:49+00:00 app[web.1]: at Promise.emit (/app/node_modules/mongoose/lib/promise.js:59:38)
2011-12-19T19:27:49+00:00 app[web.1]: at Promise.complete (/app/node_modules/mongoose/lib/promise.js:70:20)
2011-12-19T19:27:49+00:00 app[web.1]: at /app/node_modules/mongoose/lib/query.js:738:28
2011-12-19T19:27:49+00:00 app[web.1]: at model.init (/app/node_modules/mongoose/lib/model.js:181:36)
2011-12-19T19:27:49+00:00 app[web.1]: at cb (/app/node_modules/mongoose/lib/query.js:736:14)
2011-12-19T19:27:49+00:00 app[web.1]: at Array.<anonymous> (/app/node_modules/mongoose/lib/utils.js:394:16)
2011-12-19T19:27:49+00:00 app[web.1]: at model.<anonymous> (/app/node_modules/mongoose/lib/document.js:181:5)
How do I protect from such errors? For example, when I call a variable that doesn't exist, the server crashes. I understand the error but sometimes I only notice the error when deployed and the server crashes.
You can make sure your script doesn't stop by catching the 'uncaughtException' with process.on('uncaughtException', callback), like so:
process.on('uncaughtException', function (exception) {
// handle or ignore error
console.log(exception);
});
setInterval(function() {
console.log('tick, even after error');
}, 1000);
a += 1;