Skip to content

Commit b2b2edd

Browse files
committed
[email] email debug template
1 parent 311b588 commit b2b2edd

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

extend/mail.debug.example.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//file should be placed in countly/extend
2+
//edit this script and put it in countly/extend/mail.js to overwrite existing email templates and settings
3+
var nodemailer = require('nodemailer');
4+
var smtpTransport = require('nodemailer-smtp-transport');
5+
6+
//debug logging
7+
var bunyan = require('bunyan');
8+
var log = bunyan.createLogger({name: "Countly Email"});
9+
10+
//rename company
11+
var company = "Company";
12+
var email = "[email protected]";
13+
14+
module.exports = function(mail) {
15+
//define this if you need to send email from some third party service
16+
mail.smtpTransport = nodemailer.createTransport(smtpTransport({
17+
host: "myhost",
18+
secureConnection: true,
19+
port: 2525,
20+
auth: {
21+
user: "username",
22+
pass: "password"
23+
},
24+
debug: true,
25+
logger: log,
26+
}));
27+
28+
mail.sendMail = function(message, callback) {
29+
message.from = company + " <" + email + ">";
30+
mail.smtpTransport.sendMail(message, function(error) {
31+
if (error) {
32+
console.log('Error sending email');
33+
console.log(error.message);
34+
}
35+
if (callback) {
36+
callback(error);
37+
}
38+
});
39+
};
40+
41+
mail.sendMessage = function(to, subject, message, callback) {
42+
mail.sendMail({
43+
to: to,
44+
from: company + " <" + email + ">",
45+
subject: subject || "",
46+
html: message || ""
47+
}, callback);
48+
};
49+
50+
mail.sendToNewMember = function(member, memberPassword) {
51+
const password = mail.escapedHTMLString(memberPassword);
52+
53+
mail.lookup(function(err, host) {
54+
mail.sendMessage(member.email, "Your " + company + " Account",
55+
"Hi " + mail.getUserFirstName(member) + ",<br/><br/>\n" +
56+
"Your " + company + " account on <a href='" + host + "'>" + host + "</a> is created with the following details;<br/><br/>\n" +
57+
"Username: " + member.username + "<br/>Password: " + password + "<br/><br/>\n" +
58+
"Enjoy,<br/>A fellow " + company + " Admin");
59+
});
60+
};
61+
62+
mail.sendToUpdatedMember = function(member, memberPassword) {
63+
const password = mail.escapedHTMLString(memberPassword);
64+
65+
mail.lookup(function(err, host) {
66+
mail.sendMessage(member.email, "" + company + " Account - Password Change", "Hi " + mail.getUserFirstName(member) + ",<br/><br/>\n" +
67+
"Your password for your " + company + " account on <a href='" + host + "'>" + host + "</a> has been changed. Below you can find your updated account details;<br/><br/>\n" +
68+
"Username: " + member.username + "<br/>Password: " + password + "<br/><br/>\n" +
69+
"Best,<br/>A fellow " + company + " Admin");
70+
});
71+
};
72+
73+
mail.sendPasswordResetInfo = function(member, prid) {
74+
mail.lookup(function(err, host) {
75+
mail.sendMessage(member.email, "" + company + " Account - Password Reset", "Hi " + mail.getUserFirstName(member) + ",<br/><br/>\n" +
76+
"You can reset your " + company + " account password by following <a href='" + host + "/reset/" + prid + "'>this link</a>.<br/><br/>\n" +
77+
"If you did not request to reset your password ignore this email.<br/><br/>\n" +
78+
"Best,<br/>A fellow " + company + " Admin");
79+
});
80+
};
81+
82+
mail.sendAutomatedMessageError = function(member, link) {
83+
mail.lookup(function(err, host) {
84+
link = host + '/' + link;
85+
mail.sendMessage(member.email, company + " Automated Push Problem", "Hi " + mail.getUserFirstName(member) + ",,<br/><br/>\n" +
86+
"Your <a href=\"" + link + "\">automated message</a> cannot be sent due to a repeating error.\n" +
87+
"Please review message status and reactivate the message once the problem is resolved.<br/><br/>\n" +
88+
"Best,<br/>A fellow " + company + " Admin");
89+
});
90+
};
91+
};

0 commit comments

Comments
 (0)