2
2
//edit this script and put it in countly/extend/mail.js to overwrite existing email templates and settings
3
3
var nodemailer = require ( 'nodemailer' ) ;
4
4
const pluginManager = require ( '../plugins/pluginManager.js' ) ;
5
- const plugins = pluginManager . getPlugins ( ) ;
6
- //rename company
7
- var company = "Company" ;
8
-
9
5
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
+
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
+ }
19
22
}
23
+ return { email, company } ;
20
24
}
21
25
22
-
23
26
module . exports = function ( mail ) {
24
27
//define this if you need to send email from some third party service
25
28
mail . smtpTransport = nodemailer . createTransport ( {
@@ -33,6 +36,7 @@ module.exports = function(mail) {
33
36
} ) ;
34
37
35
38
mail . sendMail = function ( message , callback ) {
39
+ const { email, company } = getPluginConfig ( ) ;
36
40
message . from = company + " <" + email + ">" ;
37
41
mail . smtpTransport . sendMail ( message , function ( error ) {
38
42
if ( error ) {
@@ -46,6 +50,7 @@ module.exports = function(mail) {
46
50
} ;
47
51
48
52
mail . sendMessage = function ( to , subject , message , callback ) {
53
+ const { email, company } = getPluginConfig ( ) ;
49
54
mail . sendMail ( {
50
55
to : to ,
51
56
from : company + " <" + email + ">" ,
@@ -55,6 +60,7 @@ module.exports = function(mail) {
55
60
} ;
56
61
57
62
mail . sendToNewMember = function ( member , memberPassword ) {
63
+ const { company } = getPluginConfig ( ) ;
58
64
const password = mail . escapedHTMLString ( memberPassword ) ;
59
65
60
66
mail . lookup ( function ( err , host ) {
@@ -67,6 +73,7 @@ module.exports = function(mail) {
67
73
} ;
68
74
69
75
mail . sendToUpdatedMember = function ( member , memberPassword ) {
76
+ const { company } = getPluginConfig ( ) ;
70
77
const password = mail . escapedHTMLString ( memberPassword ) ;
71
78
72
79
mail . lookup ( function ( err , host ) {
@@ -78,6 +85,8 @@ module.exports = function(mail) {
78
85
} ;
79
86
80
87
mail . sendPasswordResetInfo = function ( member , prid ) {
88
+ const { company } = getPluginConfig ( ) ;
89
+
81
90
mail . lookup ( function ( err , host ) {
82
91
mail . sendMessage ( member . email , "" + company + " Account - Password Reset" , "Hi " + mail . getUserFirstName ( member ) + ",<br/><br/>\n" +
83
92
"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) {
87
96
} ;
88
97
89
98
mail . sendAutomatedMessageError = function ( member , link ) {
99
+ const { company } = getPluginConfig ( ) ;
100
+
90
101
mail . lookup ( function ( err , host ) {
91
102
link = host + '/' + link ;
92
103
mail . sendMessage ( member . email , company + " Automated Push Problem" , "Hi " + mail . getUserFirstName ( member ) + ",,<br/><br/>\n" +
0 commit comments