How to send STMP email from frontend (SMTPJS) [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 9 days ago.
Improve this question
I'am building a simple personal static website and I want to be able to send an email from there.
I'am not really concerned about safety because the site doesn't really have any sensitive information, it's just to showcase some simple work and then have a contact me section.
I was thinking about using SMTP.js to send an e-mail from the frontend but GMAIL doesn't allow you to do that anymore.
I was wondering how can I solve that issue and if there is really any way I can send an email from the frontend?
I just wanted to have a simple piece of code like this to work :
<head>
<title>Send Mail</title>
<script src=
"https://smtpjs.com/v3/smtp.js">
</script>
<script type="text/javascript">
function sendEmail() {
Email.send({
Host: "smtp.gmail.com",
Username: "testador",
Password: "SomeRandomPassword",
To: 'myemail#gmail.com',
From: "someEmailIHaveCreateForThisPurpose#gmail.com",
Subject: "Sending Email using javascript",
Body: "Well that was easy!!",
})
.then(function (message) {
alert("mail sent successfully")
});
}
</script>
</head>

Related

How do I fetch frontend input from with express WITHOUT using <form> [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
I am randomly wondering how to get information based on input without using the <form method = "POST" ....> using express.js how would I access the req.body of something like this from the without using a form entry on the front end? - just curious
If I understand your question correctly, you are asking how to send data in an HTTP request.
How are you sending your HTTP requests from the front-end - perhaps Axios? That's a detail worth providing in your question.
For an Axios POST method, you can provide a request body as the second parameter, with the first parameter being the URL. See the Axios documentation here: https://axios-http.com/docs/post_example
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
The second parameter is a simple JavaScript object. To populate req.body, use body-parsing middleware such as express.json().
https://expressjs.com/en/4x/api.html#req.body
If you're just using an API platform tool like Postman, then in your request Body you can choose "raw" from the radio button and then JSON from the dropdown.

Make new webpage from input [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So, what I would like to implement is something like the twitter new-user function, which makes a new page on their website based on the user's input - such as https://twitter.com/newuser
How would I go about doing this? (I am fluent in NodeJS, Express, Javascript, MongoDB - the node client too, CSS, HTML)
You can define a dynamic route in express and show user data based on url paramter.
app.get('/:userName', function (req, res) {
res.send("this is the " + req.params.userName + " Profile");
})
You shoud make a database table to store users data. (and username will be unique).
after that in your profile route you can get username from url and read user data from database based on userName parameter.

Socket.IO Best way to send messages between two users? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to know what is the best way to send messages between two users? I know you can do rooms and join them but you have to "create" them first. Think of it like chat messenger. You only show the messages you recieve between those two users.
I can do one big object but eventually that would be a big object.
What are your suggestions on handling this?
Every socket in Socket.io has its own ID. You can send messages directly to a socket, once you know that ID. Example from https://socket.io/docs/v3/rooms/index.html#Default-room
io.on('connection', socket => {
socket.on('private message', (anotherSocketId, msg) => {
socket.to(anotherSocketId).emit('private message', socket.id, msg);
});
});

Live Streaming and SSE [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to work on a project where i want to set a server which hosts videos, pictures, and texts. The main objective is to push up the media contents update to the client using Sever-Side Event.
It is more or less like digital signage player where i have to set up my own server and the client player. I'm totally new at this thing. Can someone give me any ideas on how i can do it. Just basic ideas would be great and i can search about them.
You might want to check out node-easysse and easysse-client
server
var easysse = require("easysse");
app.get("/chat-stream", easysse);
app.post("/chat", function(req, res) {
easysse.emit("chat", req.body.username, req.body.message);
});
client
<script src="easysse-client.js"></script>
<script>
var client = easysseClient.connect("/chat-stream");
client.on("chat", function(username, message){
console.log(username, "says", message);
});
$.post("/chat", {username: "mjackson", message: "hehe"});
// "mjackson says hehe"
</script>
Api docs
node-easysse API
easysse-client API

Server-side validation to prevent illegal POST requests [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
For my webapp (angular + node.js), I'm implementing a gamification system where users gain points for performing actions like answering questions, watching a video, etc. Currently, I simply post to '/api/users/updatepoints' with the user's id and number of points changed to update the database.
This is of course not secure, since a user could easily do an ajax request from the console while logged in, and I was wondering how I can prevent users from illegally sending out ajax requests? What sort of server-side validation could I use to do so?
//front end
$http.post('/api/users/updatepoints', {
kidId: xxx,
pointsChanged: yyy
})
//backend
exports.updatePoints = function(req, res) {
var kidId = req.body.kidId,
pointsChanged = req.body.pointsChanged;
User.findOne({_id: kidId}, function(err, user) {
if (err) return res.send(400);
user.points += pointsChanged;
user.save(function(err) {
if (err) return res.send(400);
return res.send(200)
});
})
}
The simple answer is "you can't".
A sufficiently determined hacker will always be able to take control of anything you are running on their computer. The only way to avoid that is to validate everything server side.
For example the only way to defeat "map hacks" in competitive online play is to never send information to the client unless that information is being displayed to the user.
If it's important, do it server side. Let the client side do its processing and validate and verify everything it sends you.
This is much too big a subject to properly discuss in a format like this though. Try doing some internet searches on preventing client hacks in games.

Categories