-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmailService.js
65 lines (57 loc) · 1.93 KB
/
EmailService.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Created by swapnil on 21-Feb-15.
*/
var nodemailer = require("nodemailer");
var emailTemplates = require('email-templates');
var path = require('path');
var templatesDir = path.resolve(__dirname, 'templates')
var emailDir = path.resolve(__dirname, 'templates/email')
var jade = require('jade');
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "[email protected]",
pass: "swapnil_1985"
}
});
module.exports.sendEmail = function() {
emailTemplates(templatesDir, function(err, template) {
if (err) {
console.log(err);
} else {
// ## Send a single email
// Prepare nodemailer transport object
var smtpTransport = nodemailer.createTransport("SMTP", {
service: "Gmail",
auth: {
user: "[email protected]",
pass: "swapnil_1985"
}
});
// An example users object with formatted email function
var locals = {
email: '[email protected]'
};
// Send a single email
template('email', locals, function (err, html) {
if (err) {
console.log(err);
} else {
var fn = jade.render(html, {filename: emailDir, user:{name : 'Anoop'}});
smtpTransport.sendMail({
from: '[email protected]',
to: locals.email,
subject: 'test mail!',
html: fn
}, function (err, responseStatus) {
if (err) {
console.log(err);
} else {
console.log(responseStatus.message);
}
});
}
});
}
});
};