cpanel email using node js nodemailer not sent mail to inbox? - smtp

while using cpanel email and nodemailer to send mail to my app user i get email sent with no errors but email don`t get in reciever inbox I using the below code
const mailOptions = {
from: "my user#gofootball.net",
to:email,
subject: 'New feedback email',
text: "hello form go sports"
};
const transporter = nodemailer.createTransport(smtpTransport({
host:'mail.gofootball.net',
port: 465 ,
secureConnection: false,
debug:true,
tls: {
rejectUnauthorized: false
},
auth: {
user: 'my user#gofootball.net',
pass: 'my user pass'
}
}));

Everything seems to be absolutely correct, except the following option:
'secureConnection: false,'
Since you are using port 465, which is the SSL SMTP port, the secureConnection should be set to true instead. This is most probably the reason for your issue. Otherwise, you might want to double-check the SMTP details that you use.

Related

Is it possible to use express.js to build rest api in frontend?

the plan is to build the web app with react.js and also build the backend using express.js specfically using rest api to connec to mySQL database....the problem is
for authentication, my supervisor doesnt want me to store password anywhere, instead he suggested me to build an authentication using the usename and password that we use to connect to mySQL database. For example, when i try to make a connection with mysqlCreateConnection method, theres a section where i have to fill out the ip address and username and password. the problem is if i do this, when the user logs out, the connection between backend and database will disconnect......
is it possible to use mySQL createconnection in the front end? so whenever the user logs in it will connect to the database directly from the frontend? once the connection is created, then use backend rest api? if this works i assume the rest api has to be hosted with the same url as the frontend, since we made the connection to mySQL database in the frontend.......but again if we do this, doesnt it defeat the purpose of backend? meaning anyone can login to the frontend and change whatever they want to the backend?
so the result will be like
within the frontend. user logs in using mySQL workbench username and password, then that username and password is going to fill out the mysql createconnection method(this method is written in the frontend). which will then try to connect to the database.
user logs in successfull
user fills out a form about a product and clicks on submit and this data is send to our rest api, and mySQL database adds the data in.
here are examples of router-token and router-session within the app if you are at express.js.
db.js
const mysql = require("mysql2")
const config = require("../../config/config.json").DB
module.exports = mysql.createPool({
host: config.host,
user: config.username,
password: config.password,
database: config.database,
waitForConnections: true,
connectionLimit: 100,
queueLimit: 0,
multipleStatements: true
})
db.fun.js
const db = require("./db").promise()
let query = async(sql, data) => {
try {
let d = await db.query(sql, data);
return d[0];
} catch (err) {
console.log(`EDB: ./app/database/db.fun.js 8rows \n${err}`);
return { err: 1, errdata: err };
}
}
module.exports = {
query: query
}
import query
(async function(){
const { query } = require("../database/db.fun");
let user = await query("SELECT * FROM users",[]);
console.log(user)
})();

Is sending login credentials to server for authentication and authorization in body with content-type: application/json acceptable?

I was looking through multiple stack overflow questions and answers but wasn't able to get anything definitive when it comes to making a request to a server for login authentication and authorization.
My question: Is sending login credentials to server for authentication and authorization in body with content-type: application/json acceptable?
const handleSubmit = (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const [email, password] = formData.values();
fetch('/login', {
method: 'POST',
headers : {'Content-Type' : 'application/json'},
body: JSON.stringify({email, password})
}).then(result =>{ //result is a ReadableStream object
return result.json(); //result.json() parses the data into useable format (json)
}).then(data => {
if(data.isAuthenticated){
handleUserAuthChange(true, ()=>{
history.push('/vehicles');
});
}
}).catch(err => console.log(err));
}
As long as you are using HTTPS, yes. This is a pretty common way of handling login requests
There is a great "tutorial" here on stackoverflow.
Unless the connection is already secure (that is, tunneled through HTTPS using SSL/TLS), your login form values will be sent in cleartext, which allows anyone eavesdropping on the line between browser and web server will be able to read logins as they pass through. This type of wiretapping is done routinely by governments, but in general, we won't address 'owned' wires other than to say this: Just use HTTPS.
In short, you want to always use HTTPS to be sure it's safe.

Session is not initializing if i run my nodejs server with ip address

I am using nodejs with express 4 framework. I have setup my node project on server but the problem is that after the login it will not redirect me to dashboard page.
When i check "req.user" after login then it gave me undefined value although its working fine in my local system.
But when i point the ip with domain name then session is initializing successfully. and it redirect me to dashboard page and also gave me req.user information.
This is my session code.
var sessionStore = new SessionStore({}, connection);
// required for passport
app.use(session({
secret: '5372E653ED6BD22E09BF14DE621CAFBFEA8B1391C056B73F3A0FECB31BD4E1B8',
cookie: { maxAge : 2592000000 },
store: sessionStore,
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
app.use(routes);
Route code (after login)
router.all('/user/*', function (req, res, next) {
if (!req.user) {
res.redirect("/login.html");
} else {
next();
}
});
Any Idea?
I think it is intentionally happening in the browser. This doesn't sound like an express issue.
Related issues here:
IP and domain create different session
Why does the session cookie work when serving from a domain but not when using an IP?

How to use X-MC-MergeVars for handlebars

I am new to mandrill and trying to setup a mail using handlebars and SMTP. My template looks like -
<span> {{userName}}, </span> Welcome to ......
This is what my mailer.js looks like (running on node.js)
var mailer = require("mailer")
, username = "**#***.com"
, password = "*********";
mailer.send(
{host: "smtp.mandrillapp.com",
port: 25,
to: "**#gmail.com",
from: "**#gmail.com",
subject: "Mail using Mandrill!",
authentication: "login",
username: "**#**.com",
password: "********",
headers: {
"X-MC-Track": "clicks",
"X-MC-Autotext": true,
"X-MC-Template": "newsFeed",
"X-MC-MergeVars": {"userName": "Pranav"},
"X-MC-MergeLanguage": "handlebars"
}
}, function(err, result){
if(err){
console.log(err);
}
}
);
I receive mail, but userName is not replaced with the userName value passed with X-MC-MergeVars and is replaced with empty string.
Am I missing something?
Thanks,
All of your mail headers need to be strings; you're currently passing a JavaScript object for the mergevars.
Try using JSON.stringify to convert the object to a string for the header:
"X-MC-MergeVars": JSON.stringify( {"userName": "Pranav"} ),

Resource not found: domain while inserting a new user with Google API

I'm trying to insert a new user under my Google Admin account:
def insertNewUser(directory_service):
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': 'testemail#mycompanydomain',
}
result = directory_service.users().insert(body=params).execute()
After executing this code I get the following error message:
googleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/admin/directory/v1/users?alt=json returned "Resource Not Found: domain">
I have no idea what can it mean and how to solve the problem? Are there any examples of inserting users using Google Admin API?
I tried adding the domain in the request but it didn't help, e.g.:
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': 'testemail#mycompanydomain',
'organizations': {
'domain': 'mycompanydomain',
}
}
or:
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': 'testemail#mycompanydomain',
'domain': 'mycompanydomain',
}
I'm quite sure I'm authenticating correctly, since I'm able to execute get-like requests, like list all current users under my account.
I tried to execute the same query using Google API explorer: https://developers.google.com/admin-sdk/directory/v1/reference/users/insert and it works fine there.
I've also seen the following post:
404 Resource Not Found: domain with Google Direcotry API and maybe the solution is similar, however I couldn't find how to create a user object with the API in Python. There are no examples available either.
I found the mistake. The domain should of course end with ".com".
The correct request is:
def insertNewUser(directory_service):
params = {
'name': {
'familyName': 'Testfamilyname',
'givenName': 'TestgivenName',
},
'password': 'testpassword',
'primaryEmail': 'testemail#mycompanydomain.com',
}
result = directory_service.users().insert(body=params).execute()