-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEmail.js
38 lines (30 loc) · 1.05 KB
/
Email.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
var nodemailer = require('nodemailer');
var router = express.Router();
app.use('/sayHello', router);
router.post('/', handleSayHello); // handle the route at yourdomain.com/sayHello
function handleSayHello(req, res) {
// Not the movie transporter!
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'example@gmail.com', // Your email id
pass: 'password' // Your password
});
}
var text = 'Hello world from \n\n' + req.body.name;
var mailOptions = {
from: 'example@gmail.com>', // sender address
to: 'receiver@destination.com', // list of receivers
subject: 'Email Example', // Subject line
text: text //, // plaintext body
// html: '<b>Hello world ✔</b>' // You can choose to send an HTML body instead
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
res.json({yo: 'error'});
}else{
console.log('Message sent: ' + info.response);
res.json({yo: info.response});
};
});