forked from parse-community/parse-server-example
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodeMailerAdapter.js
More file actions
67 lines (56 loc) · 2.58 KB
/
nodeMailerAdapter.js
File metadata and controls
67 lines (56 loc) · 2.58 KB
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
66
67
'use strict';
var nodemailer = require("nodemailer");
var SimpleNodeMailerAdapter = function SimpleNodeMailerAdapter(nodeMailerOptions) {
if (!nodeMailerOptions || !nodeMailerOptions.email || !nodeMailerOptions.password) {
throw 'NodeMailerAdapter requires an email and password.';
}
var sendMail = function sendMail(_ref) {
var smtpTransport = nodemailer.createTransport({
service: "Gmail",
auth: {
user: nodeMailerOptions.email,
pass: nodeMailerOptions.password
}
});
var to = _ref.to;
var subject = _ref.subject;
var text = _ref.text;
var data = {
from: nodeMailerOptions.fromAddress,
to: to,
subject: subject
};
if( _ref.text ) {
data.text= _ref.text;
} else {
data.html= _ref.html;
}
return new Promise(function (resolve, reject) {
smtpTransport.sendMail(data, function ( err, body ) {
if (err) {
reject(err);
} else {
resolve(body);
}
});
});
};
var sendVerificationEmail = function sendVerificationEmail(options) {
var text = "Estimado(a) "+options.user.get("name")+",\n\n"+"Bienvenido a GoodGreens! Para realizar tu pedido, por favor verifica tu correo electrónico haciendo click en el siguiente enlace:\n\n"+options.link+"\n\n"+"Usuario: "+options.user.get("email")+"\n\n"+"Estamos muy ilusionados por compartir contigo gran variedad de productos que promueven un estilo de vida saludable y en armonía con ambiente. En nuestra tienda virtual www.goodgreens.cr podrás elegir más de 400 productos frescos con los que podrás satisfacer los gustos y necesidades de toda tu familia.\n\n"+"Si tienes dudas sobre el proceso o retroalimentación para mejorar nuestro servicio, no dudes en contactarme.\n\n"+"Saludos, \nRebeca Salazar";
var to = options.user.get("email");
var subject = "Favor verificar tu correo electrónico con " + options.appName;
return sendMail({ text: text, to: to, subject: subject });
};
var sendPasswordResetEmail = function sendPasswordResetEmail(options) {
var text = "Estimado(a) "+options.user.get("name")+",\n\n"+"Haz solicitado un cambio de contraseña de tu cuenta en "+options.appName+"\n\n"+"Haz click en el siguiente enlace para cambiarla:\n\n"+options.link;
var to = options.user.get("email");
var subject = "Reestablecer tu contraseña con " + options.appName;
return sendMail({ text: text, to: to, subject: subject });
};
return Object.freeze({
sendMail: sendMail,
sendVerificationEmail: sendVerificationEmail,
sendPasswordResetEmail: sendPasswordResetEmail
});
};
module.exports = SimpleNodeMailerAdapter;