-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (43 loc) · 1.15 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require('dotenv').config()
const express= require('express');
const bodyParser = require('body-parser');
const ejs = require('ejs');
const nodemailer = require("nodemailer");
const app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.set('view engine', 'ejs');
app.use(express.static("public"));
app.get("/",function(req,res){
res.render("index")
});
app.post("/",function(req,res){
const name=req.body.name;
const email=req.body.email;
let transporter = nodemailer.createTransport({
service:'gmail',
auth:{
user:process.env.EMAIL,
pass:process.env.PASSWORD,
}
});
let mailOptions={
form:"no-reply",
to:email,
subject:"This is auto generated mail form nodemailer",
text:"Hey "+name+" you are awesome!"
}
transporter.sendMail(mailOptions,function(err,data){
if(err){
console.log(err);
res.redirect("/")
}else{
console.log(data);
res.redirect("/")
}
})
})
app.listen(3000,function(){
console.log("server spinning");
})