auth0 login to database sql server failed - javascript

I want to connect to my SQL SERVER database using this javascript code (code in https://manage.auth0.com on cloud):
function login(email, password, callback) {
var connection = sqlserver.connect({
userName: 'username',
password: 'mypassword',
server: 'TUN040474\\dblocal',
options: {
database: 'myDB',
rowCollectionOnRequestCompletion: true
}
});
I obtained this error:
connection to TUN040474\dblocal:1433 - failed Error: getaddrinfo ENOTFOUND TUN040474\dblocal TUN040474\dblocal:1433
After googling (https://community.auth0.com/t/custom-database-defining-the-server/6277) I understood that I have to do theese two steps:
configure my FireWall by adding rule for port 1433 for any IP Address
in my function replace server 'TUN040474\dblocal' by the Ip Address of my host because the code is in the cloud.
So I did them. But it still not working and i obtained this error:
"timeout : failed to connect to 41.224.17.185:1433 in 15000ms"
i have tried all ip addresses in ipconfig
this is the new code
function login(email, password, callback) {
var connection = sqlserver.connect({
userName: 'username',
password: 'mypassword',
server: '41.224.17.185', // I tried all ip addresses in ipconfig
options: {
database: 'myDB',
rowCollectionOnRequestCompletion: true
}
});
Is there anyone who has had this problem and solved it?

Related

Connection between node and mysql crash

I have a connection between Node and MySQL with a external database:
const connectionDB = mysql.createConnection({
host: '178.129.145.252',
port: 3306,
user: '',
password: '',
database: '*****'
})
when I execute my script to start it runs and I can view the users in a table, but later it crashes
enter image description here anyone knows how can I connect with the external database?
Thanks
Your code does not properly handle connection loss to MySQL server.
A quick solution would be to use connection pool.
var db_config = {
host: 'localhost',
user: 'username',
password: 'password',
database: 'example'
};
let pool = mysql.createPool(dbConfig);
pool.on('connection', function (conn) {
if (conn) {
logger.info('Connected');
}
});
// DO SOMETHING HERE
// pool.query('QUERY GOES HERE', (err, rows) => { /* Handle query response */});

How to successfully send mail using a different domain than SMTP credentials?

I want to send out an email as myemail#domain2.com while being connected to domain1.com using domain1.com SMTP credentials. Both domain1.com and domain2.com have SPF records.
I did quite a bit of research and found that you should be able to achieve this by adding "a:domain1.com" into domain2.com's SPF record. I have done as such but I still cannot successfully send out an email.
I created a test code using node.js and nodemailer to test sending out the email.
const nodemailer = require('nodemailer');
let transport = nodemailer.createTransport({
host: 'mail.domain1.com',
port: 465,
auth: {
user: 'myemail#domain1.com',
pass: 'password'
}
});
const message = {
from: 'myemail#domain2.com',
to: 'test#gmail.com',
subject: 'Testing 123',
text: 'Testing One Two Three....'
};
transport.sendMail(message, function (err, info) {
if (err) {
console.log('err: ', err);
} else {
console.log('info: ', info);
}
});
{ Error: Message failed: 550 Error458 block
at SMTPConnection._formatError (C:\Users\Admin\Desktop\testsendmail\node_modules\nodemailer\lib\smtp-connection\index.js:784:19)
at SMTPConnection._actionSMTPStream (C:\Users\Admin\Desktop\testsendmail\node_modules\nodemailer\lib\smtp-connection\index.js:1661:34)
at SMTPConnection._responseActions.push.str (C:\Users\Admin\Desktop\testsendmail\node_modules\nodemailer\lib\smtp-connection\index.js:1146:22)
at SMTPConnection._processResponse (C:\Users\Admin\Desktop\testsendmail\node_modules\nodemailer\lib\smtp-connection\index.js:942:20)
at SMTPConnection._onData (C:\Users\Admin\Desktop\testsendmail\node_modules\nodemailer\lib\smtp-connection\index.js:749:14)
at TLSSocket.SMTPConnection._onSocketData.chunk (C:\Users\Admin\Desktop\testsendmail\node_modules\nodemailer\lib\smtp-connection\index.js:195:44)
at TLSSocket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at TLSSocket.Readable.push (_stream_readable.js:219:10)
code: 'EMESSAGE',
response: '550 Error458 block',
responseCode: 550,
command: 'DATA' }
Here are the SPF Records for the 2 domains:
domain1.com:
v=spf1 mx a ~all
domain2.com:
v=spf1 a a:domain1.com mx ?all
The right way to add a second domain as a mail source is to use the include mechanism:
v=spf1 a mx include:domain2.com ~all
I can't tell from what you've posted whether this is actually the cause of the error you're getting.
You might want to look into DKIM signing and DMARC as well.
While I'm here, there's no point in having a ?all default mechanism; it's equivalent to not having an SPF record at all; use ~all if you're using DMARC, -all otherwise (though be sure that all your mail sources are nailed down before doing that).

Mailing with Node.js. Issue with the host property

I know there are many posts like this here, but I couldn't find any information that would solve my issue. So I tried using both nodemailer and emailjs.
I have this code:
This is for nodemailer
var nodemailer = require('nodemailer');
nodemailer.createTestAccount((err, account) => {
if (err) console.log(err);
// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport({
host: "smtp.Hotmail.com", // Just Hotmail doesn't work either
// port: 587,
auth: {
user: 'xxx#outlook.com',
pass: 'xxx'
}
});
// setup email data with unicode symbols
let mailOptions = {
from: `${req.body.fullName} ${req.body.email}`, // sender address
to: 'alexander.ironside#mygeorgian.ca', // list of receivers
subject: 'Email from SMWDB contact form', // Subject line
html: `<h4>Name: ${req.body.fullName}</h4>
<h4>Company: ${req.body.company}</h4>
<h4>Phone: ${req.body.phone}</h4>
<p>Message: ${req.body.message}</p>`
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message sent: %s', info.messageId);
// Preview only available when sending through an Ethereal account
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321#example.com>
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
});
});
And this for emailjs
var email = require("emailjs");
var server = email.server.connect({
user: "xxx#outlook.com",
password: "xxx",
host: "smtp-mail.outlook.com",
tls: {ciphers: "SSLv3"}
});
var message = {
text: `Test`,
from: `${req.body.fullName} <${req.body.email}>`,
to: `Alex <alexander.ironside#mygeorgian.ca>`, // list of receivers
// cc: "else <else#your-email.com>",
subject: 'Email from SMWDB contact form', // Subject line
attachment:
[
{
data: `
<h4>Name: ${req.body.fullName}</h4>
<h4>Company: ${req.body.company}</h4>
<h4>Phone: ${req.body.phone}</h4>
<p>Message: ${req.body.message}</p>`
, alternative: true
},
]
};
// send the message and get a callback with an error or details of the message that was sent
server.send(message, (err, message) => {
console.log(err || message);
});
The problem I think is that as host both docs say something like this: smtp.your-email.com, meanwhile all code examples say this: host: "Hotmail". What's the correct way?
I don't really care which package I'm using.
I have to use Hotmail/Yahoo and cannot use Gmail (Too many accounts activated with one phone number)
Now to the errors:
Emailjs throws this:
{ Error: bad response on command '
.': 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. and then there is a lot of numbers and a callback trace.
Nodemailer throws this:
{ Error: getaddrinfo ENOTFOUND smtp.Hotmail.com smtp.Hotmail.com:587
at errnoException (dns.js:50:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
code: 'ECONNECTION',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'smtp.Hotmail.com',
host: 'smtp.Hotmail.com',
port: 587,
command: 'CONN' }
I used to do this in PHP and have no idea why it's so complicated with Node, but I guess there must be a reason.
I asked a friend to create a Gmail account and it worked right away. If you hit the same problem, don't bother with anything else. Just use Google.
That's the transporter code that worked for me
var transporter = nodemailer.createTransport({
host: "smtp.gmail.com", // hostname
auth: {
user: 'xxx#gmail.com',
pass: 'xxx'
}
});

Unable to connect MySQL DB, getting ECONNREFUSED

I tried to connect the DB via MySQL Java Script as below:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "******",
user: "******",
password: "******"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
And I'm using Node to execute, While I execute the above program getting the below error message:
if (err) throw err;
^
Error: connect ECONNREFUSED XX.XXX.XX.XXX:3306
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
Also I have pinged my ip address (ping XX.XXX.XX.XXX) and can able to get the response. Can help me to connect the DB.
I had the same issue and the error resolved by adding the socketPath parameter
var connection = mysql.createConnection({
user: 'user',
password: 'pass',
socketPath: '/var/run/mysqld/mysqld.sock',
database: 'dbname'
});
I highly suggest creating a connectionPool to save your resources. Here is how I did it:
//import settings.js
const db_config = {
hostname : "localhost",
user : settings.user, //username
password : settings.password, //password
database : settings.database //db
}
//create db connection pool
const con = mysql.createPool(db_config);
So the next step is to use that connection pool! Don't be scared about the async/bluebird nature of this code, it's just how I built it.
async function query(sql, params) {
const connection = await con.getConnectionAsync();
return connection.queryAsync(sql,params)
.then(rows => rows)
.finally(() => connection.release());
}
This is grabbing the connection getConnection method (Async is from bluebird promisifying the method), and using the query method (async'd), and then finally releasing the connection back into the pool. This helps save you from memory leaks caused by unclosed TCP connections.
Make sure that you also specify the port if you have changed it from the default MySQL port as well.

NodeJS nodemailer - IIS SMTP Virtual Server

I'm trying to use nodemailer (https://www.npmjs.com/package/nodemailer) to send e-mail using a local windows server we have, with an SMTP Virtual Server.
The SMTP Virtual Server works fine, we already use Jmail in Classic ASP, pass it the server name, and email gets sent.
var nodemailer = require('nodemailer');
var options = {
host: 'SERVERNAME'
};
var transporter = nodemailer.createTransport(options);
var email = {
from: 'no-reply#domain.co.uk',
to: 'webmaster#domain.co.uk',
subject: 'hello',
text: 'hello world!'
};
var callback = function(err, info){
if (err) { throw err }
console.log('sent');
}
transporter.sendMail(email, callback);
The error I get back from this is:
Can't send mail - all recipients were rejected: 550 5.7.1 Unable to
relay for webmaster#domain.co.uk
If I update the options object to include auth, like this:
var options = {
host: 'SERVERNAME',
auth: {
user: '...',
pass: '...'
}
};
I get this error:
Invalid login: 504 5.7.4 Unrecognized authentication type
How can I use nodemailer to send e-mail using our IIS SMTP Virtual Server..?
I still don't know why the above doesn't work, pointing nodemailer to our SMTP Virtual Server. However I've worked around it.
Our SMTP Virtual Server is setup to use our Office 365 account, so I've updated my nodemailer code to go to Office 365 direct, rather than via our local server.
var options = {
host: 'SMTP.office365.com',
port: 25,
secure: false,
ignoreTLS: false,
auth: {
user: '...',
pass: '...'
},
tls: {
ciphers: 'SSLv3'
}
}
This works.

Categories

Resources