How to collect data from form (name, email, attachments) and submit them to my email using express. I didn't find a comprehensive articles on this topic. I will be grateful for the help.
I am considering you know how to submit form
To send any mail through node install popular module 'nodemailer'
1-install nodemailer module in your project directory
npm install nodemailer
2-come to the controller where you are handling form submit data on server
var express = require('express'),
nodemailer = require("nodemailer");
app = express.createServer();
app.use(express.bodyParser());
app.post('/formProcess', function (req, res) {
var data=req.body;
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "gmailPassword"
}});
smtpTransport.sendMail({ //email options
from: "Sender Name <[email protected]>",
to: "Receiver Name <[email protected]>", // receiver
subject: "Emailing with nodemailer", // subject
html: "here your data goes" // body (var data which we've declared)
}, function(error, response){ //callback
if(error){
console.log(error);
}else{
console.log("Message sent: " + res.message);
}
smtpTransport.close();
}); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With