Skip to content

Commit 10109b4

Browse files
committed
Fix: Variable placement fix & transferring changes to other mail provider
1 parent 1792e13 commit 10109b4

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

api/parts/mgmt/mail.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ else {
2727
});
2828
}
2929

30+
/**
31+
*
32+
* @returns {string} email and company name
33+
*/
34+
function getPluginConfig() {
35+
let email = null;
36+
let company = null;
37+
const pluginList = plugins.getPlugins(true);
38+
if (pluginList.indexOf('white-labeling') > -1) {
39+
try {
40+
const pluginsConfig = plugins.getConfig("white-labeling");
41+
const {emailFrom, emailCompany} = pluginsConfig;
42+
email = emailFrom && emailFrom.length > 0 ? emailFrom : null;
43+
company = emailCompany && emailCompany.length > 0 ? emailCompany : null;
44+
if (email && email.length && company && company.length) {
45+
return company + " <" + email + ">";
46+
}
47+
}
48+
catch (error) {
49+
console.log('Error getting plugins config', error);
50+
}
51+
}
52+
return null;
53+
}
54+
3055
/*
3156
Use the below transport to send mails through Gmail
3257
@@ -63,7 +88,8 @@ else {
6388
* @param {function} callback - function to call when its done
6489
**/
6590
mail.sendMail = function(message, callback) {
66-
message.from = config.mail && config.mail.strings && config.mail.strings.from || message.from || "Countly";
91+
const whiteLabelingConfig = getPluginConfig();
92+
message.from = whiteLabelingConfig || config.mail && config.mail.strings && config.mail.strings.from || message.from || "Countly";
6793
mail.smtpTransport.sendMail(message, function(error) {
6894
if (error) {
6995
console.log('Error sending email');
@@ -83,9 +109,10 @@ mail.sendMail = function(message, callback) {
83109
* @param {function} callback - function to call when its done
84110
**/
85111
mail.sendMessage = function(to, subject, message, callback) {
112+
const whiteLabelingConfig = getPluginConfig();
86113
mail.sendMail({
87114
to: to,
88-
from: config.mail && config.mail.strings && config.mail.strings.from || "Countly",
115+
from: whiteLabelingConfig || config.mail && config.mail.strings && config.mail.strings.from || "Countly",
89116
subject: subject || "",
90117
html: message || ""
91118
}, callback);

extend/mail.example.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@
33
var nodemailer = require('nodemailer');
44
const pluginManager = require('../plugins/pluginManager.js');
55

6-
function getPluginConfig() {
7-
//rename company
8-
var company = "Company";
9-
var email = "[email protected]";
6+
//rename company
7+
var company = "Company";
8+
var email = "[email protected]";
109

10+
function getPluginConfig() {
1111
const plugins = pluginManager.getPlugins(true);
12+
let _email = email;
13+
let _company = company;
14+
1215
if (plugins.indexOf('white-labeling') > -1) {
1316
try {
1417
const pluginsConfig = pluginManager.getConfig("white-labeling");
1518
const {emailFrom, emailCompany} = pluginsConfig;
16-
email = emailFrom && emailFrom.length > 0 ? emailFrom : email;
17-
company = emailCompany && emailCompany.length > 0 ? emailCompany : company;
19+
_email = emailFrom && emailFrom.length > 0 ? emailFrom : email;
20+
_company = emailCompany && emailCompany.length > 0 ? emailCompany : company;
1821
}
1922
catch (error) {
2023
console.log('Error getting plugins config', error);
2124
}
2225
}
23-
return { email, company };
26+
return { email: _email, company: _company };
2427
}
2528

2629
module.exports = function(mail) {

0 commit comments

Comments
 (0)