Skip to content

Commit

Permalink
Merge pull request #3 from hispanic/notif-sender-name
Browse files Browse the repository at this point in the history
Allow for customizing the name of the sender to put on notification emails
  • Loading branch information
hispanic authored Dec 5, 2020
2 parents 46f93b5 + 674ae24 commit 7c0853a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ const schema = {
env: 'EMAIL_DOMAIN'
},
fromAddress: {
doc: 'Email address to send notifications from. Will be overridden by a `notifications.fromAddress` parameter in the site config, if one is set.',
doc: 'Email address to send notifications from.',
format: String,
default: '[email protected]',
env: 'EMAIL_FROM'
},
fromName: {
doc: 'Name of the sender to put on notification emails.',
format: String,
default: 'Staticman',
env: 'EMAIL_FROM_NAME'
}
},
env: {
Expand Down
2 changes: 1 addition & 1 deletion lib/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Notification.prototype.send = function (to, fields, options, data) {

return new Promise((resolve, reject) => {
let payload = {
from: `Staticman <${config.get('email.fromAddress')}>`,
from: `${config.get('email.fromName')} <${config.get('email.fromAddress')}>`,
to,
subject,
html: this._buildMessage(fields, options, data)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lib/Notification.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe('Notification interface', () => {

expect(mockSendFn.mock.calls.length).toBe(1)
expect(mockSendFn.mock.calls[0][0]).toEqual({
from: `Staticman <${config.get('email.fromAddress')}>`,
'h:Reply-To': `Staticman <${config.get('email.fromAddress')}>`,
from: `${config.get('email.fromName')} <${config.get('email.fromAddress')}>`,
'h:Reply-To': `${config.get('email.fromName')} <${config.get('email.fromAddress')}>`,
to: recipient,
subject: `New reply on "${mockData.data.siteName}"`,
html: message
Expand Down

0 comments on commit 7c0853a

Please sign in to comment.