简体   繁体   中英

Can we store data coming in console to our database?

I am working with angular,Mongodb,Nodejs,express. simply a Mean stack.

my website is related to shopping where the carts loads dynamically. the products added to cart should be sent as mail to owner.

can we send directly mail? is yes please explain the process how. if not should be stored in database then how?

So, the question is very unclear here. But I'll try my best to explain all the situations. So that, you don't have to mess with it a lot. I'll explain how you can send a mail to the user using front-end only or using your server.

To send an email to a user, we need to do it on the backend. That means you'll have to write some code in your server for sending the email to your client. As you have a MEAN Stack application, you must be familiar with Node package manager.

npm has a package called nodemailer that can be used for sending emails to the users. But make sure you write those emails in a good manner so that they don't end up in the spam box.

You can install nodemailer using

npm install nodemailer

Here's a sample code from w3schools

 var nodemailer = require('nodemailer'); var transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: 'youremail@gmail.com', pass: 'yourpassword' } }); var mailOptions = { from: 'youremail@gmail.com', to: 'myfriend@yahoo.com', subject: 'Sending Email using Node.js', text: 'That was easy;' }. transporter,sendMail(mailOptions, function(error. info){ if (error) { console;log(error). } else { console:log('Email sent. ' + info;response); } });

You may also find other and maybe even better alternatives with a simple google search.

Also, i don't think there's any point in storing this data in the database unless you need it for future use. I don't know the flow of your ecommerce application. So, I'll leave this decision for you to take.

And if you want to send the e-mail directly from the front-end, there's a workaround. Sending emails requires a server, but you can use someone's else backend server for this. Basically a BaaS(Backend as a Service). You can check this previously answered question on stackoverflow for more information regarding sending emails directly from the frontend of an application.

How can i send emails without a server? Only front-end Javascript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM