Skip to content

Commit 1792e13

Browse files
committed
[SER-647] Fix: Whitelabeling add emailing parameters
1 parent 8122bc7 commit 1792e13

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

extend/mail.example.js

+25-14
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@
22
//edit this script and put it in countly/extend/mail.js to overwrite existing email templates and settings
33
var nodemailer = require('nodemailer');
44
const pluginManager = require('../plugins/pluginManager.js');
5-
const plugins = pluginManager.getPlugins();
6-
//rename company
7-
var company = "Company";
8-
var email = "[email protected]";
95

10-
if (plugins.indexOf('white-labeling') > -1) {
11-
try {
12-
const pluginsConfig = pluginManager.getConfig("white-labeling");
13-
const {emailFrom, emailCompany} = pluginsConfig;
14-
email = emailFrom && emailFrom.length > 0 ? emailFrom : email;
15-
company = emailCompany && emailCompany.length > 0 ? emailCompany : company;
16-
}
17-
catch (error) {
18-
console.log('Error getting plugins config', error);
6+
function getPluginConfig() {
7+
//rename company
8+
var company = "Company";
9+
var email = "[email protected]";
10+
11+
const plugins = pluginManager.getPlugins(true);
12+
if (plugins.indexOf('white-labeling') > -1) {
13+
try {
14+
const pluginsConfig = pluginManager.getConfig("white-labeling");
15+
const {emailFrom, emailCompany} = pluginsConfig;
16+
email = emailFrom && emailFrom.length > 0 ? emailFrom : email;
17+
company = emailCompany && emailCompany.length > 0 ? emailCompany : company;
18+
}
19+
catch (error) {
20+
console.log('Error getting plugins config', error);
21+
}
1922
}
23+
return { email, company };
2024
}
2125

22-
2326
module.exports = function(mail) {
2427
//define this if you need to send email from some third party service
2528
mail.smtpTransport = nodemailer.createTransport({
@@ -33,6 +36,7 @@ module.exports = function(mail) {
3336
});
3437

3538
mail.sendMail = function(message, callback) {
39+
const { email, company } = getPluginConfig();
3640
message.from = company + " <" + email + ">";
3741
mail.smtpTransport.sendMail(message, function(error) {
3842
if (error) {
@@ -46,6 +50,7 @@ module.exports = function(mail) {
4650
};
4751

4852
mail.sendMessage = function(to, subject, message, callback) {
53+
const { email, company } = getPluginConfig();
4954
mail.sendMail({
5055
to: to,
5156
from: company + " <" + email + ">",
@@ -55,6 +60,7 @@ module.exports = function(mail) {
5560
};
5661

5762
mail.sendToNewMember = function(member, memberPassword) {
63+
const { company } = getPluginConfig();
5864
const password = mail.escapedHTMLString(memberPassword);
5965

6066
mail.lookup(function(err, host) {
@@ -67,6 +73,7 @@ module.exports = function(mail) {
6773
};
6874

6975
mail.sendToUpdatedMember = function(member, memberPassword) {
76+
const { company } = getPluginConfig();
7077
const password = mail.escapedHTMLString(memberPassword);
7178

7279
mail.lookup(function(err, host) {
@@ -78,6 +85,8 @@ module.exports = function(mail) {
7885
};
7986

8087
mail.sendPasswordResetInfo = function(member, prid) {
88+
const { company } = getPluginConfig();
89+
8190
mail.lookup(function(err, host) {
8291
mail.sendMessage(member.email, "" + company + " Account - Password Reset", "Hi " + mail.getUserFirstName(member) + ",<br/><br/>\n" +
8392
"You can reset your " + company + " account password by following <a href='" + host + "/reset/" + prid + "'>this link</a>.<br/><br/>\n" +
@@ -87,6 +96,8 @@ module.exports = function(mail) {
8796
};
8897

8998
mail.sendAutomatedMessageError = function(member, link) {
99+
const { company } = getPluginConfig();
100+
90101
mail.lookup(function(err, host) {
91102
link = host + '/' + link;
92103
mail.sendMessage(member.email, company + " Automated Push Problem", "Hi " + mail.getUserFirstName(member) + ",,<br/><br/>\n" +

0 commit comments

Comments
 (0)