-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: modify default from address
- Loading branch information
1 parent
6fff8b5
commit 5fe2ad2
Showing
10 changed files
with
54 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -810,9 +810,7 @@ const config: Config<ConfigSchema> = convict({ | |
}) | ||
|
||
// If mailFrom was not set in an env var, set it using the app_name | ||
const defaultMailFrom = `${config.get( | ||
'APP_NAME' | ||
)} <[email protected]>` | ||
const defaultMailFrom = `${config.get('APP_NAME')} <[email protected]>` | ||
config.set('mailFrom', config.get('mailFrom') || defaultMailFrom) | ||
|
||
// Override some defaults | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,13 @@ export const isDefaultFromAddress = (from: string): boolean => { | |
const { fromAddress: defaultFromAddress } = parseFromAddress( | ||
config.get('mailFrom') | ||
) | ||
return fromAddress === defaultFromAddress | ||
// As part of a PSD directive, we have changed the defaultFromAddress to [email protected]. | ||
// To prevent any breaking changes, we must now support both the new and old default address | ||
const allowedDefaultAddresses = [ | ||
defaultFromAddress, | ||
'[email protected]', | ||
] | ||
return allowedDefaultAddresses.includes(fromAddress) | ||
} | ||
|
||
export const fromAddressValidator = Joi.string() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ export interface EmailMiddleware { | |
} | ||
|
||
export const INVALID_FROM_ADDRESS_ERROR_MESSAGE = | ||
"Invalid 'from' email address, which must be either the default donotreply@mail.postman.gov.sg or the user's email (which requires setup with Postman team). Contact us to learn more." | ||
"Invalid 'from' email address, which must be either the default info@mail.postman.gov.sg or the user's email (which requires setup with Postman team). Contact us to learn more." | ||
|
||
export const UNVERIFIED_FROM_ADDRESS_ERROR_MESSAGE = | ||
'From Address has not been verified. Contact us to learn more.' | ||
|
@@ -223,10 +223,17 @@ export const InitEmailMiddleware = ( | |
const { fromName: defaultFromName, fromAddress: defaultFromAddress } = | ||
parseFromAddress(config.get('mailFrom')) | ||
|
||
// As part of a PSD directive, we have changed the defaultFromAddress to [email protected]. | ||
// To prevent any breaking changes, we must now support both the new and old default address | ||
const allowedDefaultAddresses = [ | ||
defaultFromAddress, | ||
'[email protected]', | ||
] | ||
|
||
if ( | ||
// user enters an email that is neither their own nor donotreply@mail.postman.gov.sg | ||
// user enters an email that is neither their own nor info@mail.postman.gov.sg | ||
fromAddress !== userEmail && | ||
fromAddress !== defaultFromAddress | ||
allowedDefaultAddresses.includes(fromAddress) | ||
) { | ||
logger.error({ | ||
message: INVALID_FROM_ADDRESS_ERROR_MESSAGE, | ||
|
@@ -304,7 +311,7 @@ export const InitEmailMiddleware = ( | |
|
||
/** | ||
* Verifies the user's email address to see if it can be used as custom 'from' address | ||
* - if it is the default donotreply@mail.postman.gov.sg, return immediately | ||
* - if it is the default info@mail.postman.gov.sg, return immediately | ||
* - else, make network calls to AWS SES and the user's domain to verify DNS settings are set up properly. | ||
*/ | ||
const verifyFromAddress = async ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
expect.objectContaining({ | ||
message: `Template for campaign ${campaignId} updated`, | ||
template: expect.objectContaining({ | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
reply_to: '[email protected]', | ||
}), | ||
}) | ||
|
@@ -106,7 +106,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
const res = await request(app) | ||
.put(`/campaign/${campaignId}/email/template`) | ||
.send({ | ||
from: 'Agency.gov.sg <donotreply@mail.postman.gov.sg>', | ||
from: 'Agency.gov.sg <info@mail.postman.gov.sg>', | ||
subject: 'test', | ||
body: 'test', | ||
reply_to: '[email protected]', | ||
|
@@ -116,7 +116,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
expect.objectContaining({ | ||
message: `Template for campaign ${campaignId} updated`, | ||
template: expect.objectContaining({ | ||
from: 'Agency.gov.sg via Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Agency.gov.sg via Postman <info@mail.postman.gov.sg>', | ||
reply_to: '[email protected]', | ||
}), | ||
}) | ||
|
@@ -127,7 +127,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
const res = await request(app) | ||
.put(`/campaign/${campaignId}/email/template`) | ||
.send({ | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
subject: 'test', | ||
body: 'test', | ||
reply_to: '[email protected]', | ||
|
@@ -137,7 +137,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
expect.objectContaining({ | ||
message: `Template for campaign ${campaignId} updated`, | ||
template: expect.objectContaining({ | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
reply_to: '[email protected]', | ||
}), | ||
}) | ||
|
@@ -194,7 +194,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
const res = await request(app) | ||
.put(`/campaign/${campaignId}/email/template`) | ||
.send({ | ||
from: 'Custom Name <donotreply@mail.postman.gov.sg>', | ||
from: 'Custom Name <info@mail.postman.gov.sg>', | ||
subject: 'test', | ||
body: 'test', | ||
reply_to: '[email protected]', | ||
|
@@ -205,7 +205,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
expect.objectContaining({ | ||
message: `Template for campaign ${campaignId} updated`, | ||
template: expect.objectContaining({ | ||
from: `Custom Name ${mailVia} <donotreply@mail.postman.gov.sg>`, | ||
from: `Custom Name ${mailVia} <info@mail.postman.gov.sg>`, | ||
reply_to: '[email protected]', | ||
}), | ||
}) | ||
|
@@ -266,7 +266,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
const res = await request(app) | ||
.put(`/campaign/${campaignId}/email/template`) | ||
.send({ | ||
from: `Custom Name ${mailVia} <donotreply@mail.postman.gov.sg>`, | ||
from: `Custom Name ${mailVia} <info@mail.postman.gov.sg>`, | ||
subject: 'test', | ||
body: 'test', | ||
reply_to: '[email protected]', | ||
|
@@ -277,7 +277,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
expect.objectContaining({ | ||
message: `Template for campaign ${campaignId} updated`, | ||
template: expect.objectContaining({ | ||
from: `Custom Name ${mailVia} <donotreply@mail.postman.gov.sg>`, | ||
from: `Custom Name ${mailVia} <info@mail.postman.gov.sg>`, | ||
reply_to: '[email protected]', | ||
}), | ||
}) | ||
|
@@ -347,7 +347,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
expect.objectContaining({ | ||
message: `Template for campaign ${protectedCampaignId} updated`, | ||
template: expect.objectContaining({ | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
reply_to: '[email protected]', | ||
}), | ||
}) | ||
|
@@ -391,7 +391,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
message: | ||
'Please re-upload your recipient list as template has changed.', | ||
template: expect.objectContaining({ | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
reply_to: '[email protected]', | ||
}), | ||
}) | ||
|
@@ -418,7 +418,7 @@ describe('PUT /campaign/{campaignId}/email/template', () => { | |
template: { | ||
subject: 'test', | ||
body: 'test {{name}}', | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
reply_to: '[email protected]', | ||
params: ['name'], | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ describe(`${emailTransactionalRoute}/send`, () => { | |
recipient: '[email protected]', | ||
subject: 'subject', | ||
body: '<p>body</p>', | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
reply_to: '[email protected]', | ||
} | ||
const generateRandomSmallFile = () => { | ||
|
@@ -150,7 +150,7 @@ describe(`${emailTransactionalRoute}/send`, () => { | |
.spyOn(EmailService, 'sendEmail') | ||
.mockResolvedValue(true) | ||
|
||
const from = 'Hello <donotreply@mail.postman.gov.sg>' | ||
const from = 'Hello <info@mail.postman.gov.sg>' | ||
const res = await request(app) | ||
.post(endpoint) | ||
.set('Authorization', `Bearer ${apiKey}`) | ||
|
@@ -172,14 +172,14 @@ describe(`${emailTransactionalRoute}/send`, () => { | |
expect(transactionalEmail).not.toBeNull() | ||
expect(transactionalEmail).toMatchObject({ | ||
recipient: validApiCall.recipient, | ||
from: 'Hello <donotreply@mail.postman.gov.sg>', | ||
from: 'Hello <info@mail.postman.gov.sg>', | ||
status: TransactionalEmailMessageStatus.Accepted, | ||
errorCode: null, | ||
}) | ||
expect(transactionalEmail?.params).toMatchObject({ | ||
subject: validApiCall.subject, | ||
body: validApiCall.body, | ||
from: 'Hello <donotreply@mail.postman.gov.sg>', | ||
from: 'Hello <info@mail.postman.gov.sg>', | ||
reply_to: user.email, | ||
}) | ||
}) | ||
|
@@ -479,7 +479,7 @@ describe(`${emailTransactionalRoute}/send`, () => { | |
.field('recipient', validApiCallAttachment.recipient) | ||
.field('subject', validApiCallAttachment.subject) | ||
.field('body', validApiCallAttachment.body) | ||
.field('from', 'Postman <donotreply@mail.postman.gov.sg>') | ||
.field('from', 'Postman <info@mail.postman.gov.sg>') | ||
.field('reply_to', validApiCallAttachment.reply_to) | ||
.attach('attachments', validAttachment, validAttachmentName) | ||
expect(res.status).toBe(403) | ||
|
@@ -971,29 +971,29 @@ describe(`GET ${emailTransactionalRoute}`, () => { | |
const endpoint = emailTransactionalRoute | ||
const acceptedMessage = { | ||
recipient: '[email protected]', | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
params: { | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
subject: 'Test', | ||
body: 'Test Body', | ||
}, | ||
status: TransactionalEmailMessageStatus.Accepted, | ||
} | ||
const sentMessage = { | ||
recipient: '[email protected]', | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
params: { | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
subject: 'Test', | ||
body: 'Test Body', | ||
}, | ||
status: TransactionalEmailMessageStatus.Sent, | ||
} | ||
const deliveredMessage = { | ||
recipient: '[email protected]', | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
params: { | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
subject: 'Test', | ||
body: 'Test Body', | ||
}, | ||
|
@@ -1330,9 +1330,9 @@ describe(`GET ${emailTransactionalRoute}/:emailId`, () => { | |
const message = await EmailMessageTransactional.create({ | ||
userId: user.id, | ||
recipient: '[email protected]', | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
params: { | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
subject: 'Test', | ||
body: 'Test Body', | ||
}, | ||
|
@@ -1368,9 +1368,9 @@ describe(`GET ${emailTransactionalRoute}/:emailId`, () => { | |
const message = await EmailMessageTransactional.create({ | ||
userId: user.id, | ||
recipient: '[email protected]', | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
params: { | ||
from: 'Postman <donotreply@mail.postman.gov.sg>', | ||
from: 'Postman <info@mail.postman.gov.sg>', | ||
subject: 'Test', | ||
body: 'Test Body', | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export const API_URL = | ||
process.env.API_URL || 'https://api-staging.postman.gov.sg'; | ||
process.env.API_URL || "https://api-staging.postman.gov.sg"; | ||
export const API_KEY = process.env.API_KEY as string; | ||
export const MAILBOX = process.env.MAIL_BOX || '[email protected]'; | ||
export const MAILBOX = process.env.MAIL_BOX || "[email protected]"; | ||
|
||
export const DASHBOARD_URL = | ||
process.env.DASHBOARD_URL || 'https://staging.postman.gov.sg'; | ||
export const POSTMAN_FROM = 'donotreply@mail.postman.gov.sg'; | ||
process.env.DASHBOARD_URL || "https://staging.postman.gov.sg"; | ||
export const POSTMAN_FROM = "info@mail.postman.gov.sg"; | ||
|
||
export const SMS_NUMBER = process.env.SMS_NUMBER as string; | ||
export const TWILIO_ACC_SID = process.env.TWILIO_ACC_SID as string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters