Skip to content
Snippets Groups Projects
Unverified Commit 34259869 authored by Marcelo Schmidt's avatar Marcelo Schmidt
Browse files

Add header and footer to e-mails

parent 037dc095
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,10 @@ Meteor.methods ...@@ -40,6 +40,10 @@ Meteor.methods
Function(localeFn)() Function(localeFn)()
html = "" html = ""
header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || "")
footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || "")
RocketChat.models.Messages.findByRoomIdAndMessageIds(data.rid, data.messages, { sort: { ts: 1 } }).forEach (message) -> RocketChat.models.Messages.findByRoomIdAndMessageIds(data.rid, data.messages, { sort: { ts: 1 } }).forEach (message) ->
dateTime = moment(message.ts).locale(data.language).format('L LT') dateTime = moment(message.ts).locale(data.language).format('L LT')
html += "<p style='margin-bottom: 5px'><b>#{message.u.username}</b> <span style='color: #aaa; font-size: 12px'>#{dateTime}</span><br />" + RocketChat.Message.parse(message, data.language) + "</p>" html += "<p style='margin-bottom: 5px'><b>#{message.u.username}</b> <span style='color: #aaa; font-size: 12px'>#{dateTime}</span><br />" + RocketChat.Message.parse(message, data.language) + "</p>"
...@@ -50,7 +54,7 @@ Meteor.methods ...@@ -50,7 +54,7 @@ Meteor.methods
from: RocketChat.settings.get('From_Email') from: RocketChat.settings.get('From_Email')
replyTo: email replyTo: email
subject: data.subject subject: data.subject
html: html html: header + html + footer
console.log 'Sending email to ' + emails.join(', ') console.log 'Sending email to ' + emails.join(', ')
......
...@@ -37,7 +37,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { ...@@ -37,7 +37,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
message.html = message.html.replace(token.token, token.text); message.html = message.html.replace(token.token, token.text);
}); });
} }
message.html = message.html.replace(/\n/gm, '<br/>');
var header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || '');
var footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || '');
message.html = header + message.html.replace(/\n/gm, '<br/>') + footer;
RocketChat.models.Subscriptions.findWithSendEmailByRoomId(room._id).forEach((sub) => { RocketChat.models.Subscriptions.findWithSendEmailByRoomId(room._id).forEach((sub) => {
switch (sub.emailNotifications) { switch (sub.emailNotifications) {
......
...@@ -9,11 +9,14 @@ Meteor.methods ...@@ -9,11 +9,14 @@ Meteor.methods
this.unblock() this.unblock()
header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || '');
footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || '');
Email.send Email.send
to: user.emails[0].address to: user.emails[0].address
from: RocketChat.settings.get('From_Email') from: RocketChat.settings.get('From_Email')
subject: "SMTP Test Email" subject: "SMTP Test Email"
html: "You have successfully sent an email" html: header + "<p>You have successfully sent an email</p>" + footer
console.log 'Sending email to ' + user.emails[0].address console.log 'Sending email to ' + user.emails[0].address
......
...@@ -9,6 +9,9 @@ Mailer.sendMail = (from, subject, body, dryrun, query) -> ...@@ -9,6 +9,9 @@ Mailer.sendMail = (from, subject, body, dryrun, query) ->
if body.indexOf('[unsubscribe]') is -1 if body.indexOf('[unsubscribe]') is -1
throw new Meteor.Error 'error-missing-unsubscribe-link', 'You must provide the [unsubscribe] link.', { function: 'Mailer.sendMail' } throw new Meteor.Error 'error-missing-unsubscribe-link', 'You must provide the [unsubscribe] link.', { function: 'Mailer.sendMail' }
header = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Header') || '');
footer = RocketChat.placeholders.replace(RocketChat.settings.get('Email_Footer') || '');
userQuery = { "mailer.unsubscribed": { $exists: 0 } } userQuery = { "mailer.unsubscribed": { $exists: 0 } }
if query if query
userQuery = { $and: [ userQuery, EJSON.parse(query) ] } userQuery = { $and: [ userQuery, EJSON.parse(query) ] }
...@@ -32,7 +35,7 @@ Mailer.sendMail = (from, subject, body, dryrun, query) -> ...@@ -32,7 +35,7 @@ Mailer.sendMail = (from, subject, body, dryrun, query) ->
to: email to: email
from: from from: from
subject: subject subject: subject
html: html html: header + html + footer
console.log 'Sending email to ' + email console.log 'Sending email to ' + email
...@@ -55,6 +58,6 @@ Mailer.sendMail = (from, subject, body, dryrun, query) -> ...@@ -55,6 +58,6 @@ Mailer.sendMail = (from, subject, body, dryrun, query) ->
to: email to: email
from: from from: from
subject: subject subject: subject
html: html html: header + html + footer
console.log 'Sending email to ' + email console.log 'Sending email to ' + email
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment