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
+ //rename company
7
+ var company = "Company" ;
8
+
9
+
10
+ module . exports = function ( mail ) {
11
+ //define this if you need to send email from some third party service
12
+ mail . smtpTransport = nodemailer . createTransport ( smtpTransport ( {
13
+ host : "myhost" ,
14
+ secureConnection : true ,
15
+ port : 2525 ,
16
+ auth : {
17
+ user : "username" ,
18
+ pass : "password"
19
+ }
20
+ } ) ) ;
21
+
22
+ mail . sendMail = function ( message , callback ) {
23
+ message . from = company + " <" + email + ">" ;
24
+ mail . smtpTransport . sendMail ( message , function ( error ) {
25
+ if ( error ) {
26
+ console . log ( 'Error sending email' ) ;
27
+ console . log ( error . message ) ;
28
+ }
29
+ if ( callback ) {
30
+ callback ( error ) ;
31
+ }
32
+ } ) ;
33
+ } ;
34
+
35
+ mail . sendMessage = function ( to , subject , message , callback ) {
36
+ mail . sendMail ( {
37
+ to : to ,
38
+ from : company + " <" + email + ">" ,
39
+ subject : subject || "" ,
40
+ html : message || ""
41
+ } , callback ) ;
42
+ } ;
43
+
44
+ mail . sendToNewMember = function ( member , memberPassword ) {
45
+ const password = mail . escapedHTMLString ( memberPassword ) ;
46
+
47
+ mail . lookup ( function ( err , host ) {
48
+ mail . sendMessage ( member . email , "Your " + company + " Account" ,
49
+ "Hi " + mail . getUserFirstName ( member ) + ",<br/><br/>\n" +
50
+ "Your " + company + " account on <a href='" + host + "'>" + host + "</a> is created with the following details;<br/><br/>\n" +
51
+ "Username: " + member . username + "<br/>Password: " + password + "<br/><br/>\n" +
52
+ "Enjoy,<br/>A fellow " + company + " Admin" ) ;
53
+ } ) ;
54
+ } ;
55
+
56
+ mail . sendToUpdatedMember = function ( member , memberPassword ) {
57
+ const password = mail . escapedHTMLString ( memberPassword ) ;
58
+
59
+ mail . lookup ( function ( err , host ) {
60
+ mail . sendMessage ( member . email , "" + company + " Account - Password Change" , "Hi " + mail . getUserFirstName ( member ) + ",<br/><br/>\n" +
61
+ "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" +
62
+ "Username: " + member . username + "<br/>Password: " + password + "<br/><br/>\n" +
63
+ "Best,<br/>A fellow " + company + " Admin" ) ;
64
+ } ) ;
65
+ } ;
66
+
67
+ mail . sendPasswordResetInfo = function ( member , prid ) {
68
+ mail . lookup ( function ( err , host ) {
69
+ mail . sendMessage ( member . email , "" + company + " Account - Password Reset" , "Hi " + mail . getUserFirstName ( member ) + ",<br/><br/>\n" +
70
+ "You can reset your " + company + " account password by following <a href='" + host + "/reset/" + prid + "'>this link</a>.<br/><br/>\n" +
71
+ "If you did not request to reset your password ignore this email.<br/><br/>\n" +
72
+ "Best,<br/>A fellow " + company + " Admin" ) ;
73
+ } ) ;
74
+ } ;
75
+
76
+ mail . sendAutomatedMessageError = function ( member , link ) {
77
+ mail . lookup ( function ( err , host ) {
78
+ link = host + '/' + link ;
79
+ mail . sendMessage ( member . email , company + " Automated Push Problem" , "Hi " + mail . getUserFirstName ( member ) + ",,<br/><br/>\n" +
80
+ "Your <a href=\"" + link + "\">automated message</a> cannot be sent due to a repeating error.\n" +
81
+ "Please review message status and reactivate the message once the problem is resolved.<br/><br/>\n" +
82
+ "Best,<br/>A fellow " + company + " Admin" ) ;
83
+ } ) ;
84
+ } ;
85
+ } ;
0 commit comments