-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add Mailtrap logo to README * chore: remove config to check JS * chore: remove index.d.ts * feat: add Mailtrap support
- Loading branch information
1 parent
88b41f3
commit 87c1639
Showing
3 changed files
with
71 additions
and
77 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
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 |
---|---|---|
|
@@ -79,7 +79,8 @@ module.exports = { | |
'An override for the default "from" email that\'s been configured.', | ||
example: '[email protected]', | ||
isEmail: true, | ||
defaultsTo: sails.config.mail.from.address || process.env.MAIL_FROM_ADDRESS | ||
defaultsTo: | ||
sails.config.mail.from.address || process.env.MAIL_FROM_ADDRESS | ||
}, | ||
|
||
fromName: { | ||
|
@@ -91,7 +92,7 @@ module.exports = { | |
replyTo: { | ||
description: 'An email address that will appear on the Reply-To: field', | ||
example: '[email protected]', | ||
defaultsTo: sails.config.mail.replyTo || process.env.MAIL_REPLY_TO | ||
defaultsTo: sails.config.mail.replyTo || process.env.MAIL_REPLY_TO | ||
}, | ||
|
||
layout: { | ||
|
@@ -111,6 +112,28 @@ module.exports = { | |
}, | ||
text: { | ||
example: 'Hello world' | ||
}, | ||
// Mailtrap transport specific options | ||
templateUuid: { | ||
type: 'string', | ||
description: 'The UUID of the template to use.' | ||
}, | ||
templateVariables: { | ||
type: 'ref', | ||
description: 'An object with the variables to use in the template.' | ||
}, | ||
category: { | ||
type: 'string', | ||
description: 'The category of the email.' | ||
}, | ||
customVariables: { | ||
type: 'ref', | ||
description: 'An object with the custom variables to use in the email.' | ||
}, | ||
testInboxId: { | ||
type: 'string', | ||
description: 'The ID of the test inbox to use.', | ||
defaultsTo: process.env.MAILTRAP_TEST_INBOX_ID | ||
} | ||
}, | ||
|
||
|
@@ -133,7 +156,13 @@ module.exports = { | |
text, | ||
cc, | ||
bcc, | ||
attachments | ||
attachments, | ||
// Mailtrap transport specific options | ||
templateUuid, | ||
templateVariables, | ||
category, | ||
customVariables, | ||
testInboxId | ||
}) { | ||
if (template && !template.startsWith('email-')) { | ||
sails.log.warn( | ||
|
@@ -227,6 +256,43 @@ module.exports = { | |
}) | ||
sails.log.debug('Email sent: %s', smtpInfo.messageId) | ||
break | ||
case 'mailtrap': | ||
const { MailtrapClient } = getModule('mailtrap') | ||
testInboxId = testInboxId | ||
? testInboxId | ||
: sails.config.mail.mailers[mailer]?.testInboxId | ||
const mailtrapClientOptions = { | ||
token: | ||
sails.config.mail.mailers[mailer]?.token || | ||
process.env.MAILTRAP_TOKEN, | ||
testInboxId, | ||
accountId: | ||
sails.config.mail.mailers[mailer]?.accountId || | ||
process.env.MAILTRAP_ACCOUNT_ID | ||
} | ||
const mailtrap = new MailtrapClient({ ...mailtrapClientOptions }) | ||
const mail = { | ||
category, | ||
from: { name: fromName, email: fromAddress }, | ||
to: [{ email: to }], | ||
subject, | ||
text, | ||
html, | ||
attachments, | ||
template_uuid: templateUuid, | ||
template_variables: templateVariables, | ||
custom_variables: customVariables | ||
} | ||
let mailtrapInfo | ||
if (testInboxId) { | ||
mailtrapInfo = await mailtrap.testing.send({ ...mail }) | ||
} else { | ||
mailtrapInfo = await mailtrap.send({ ...mail }) | ||
} | ||
|
||
mailtrapInfo = await mailtrap.send({ ...mail }) | ||
sails.log.debug('Email sent: %s', mailtrapInfo.message_ids.join(', ')) | ||
break | ||
case 'resend': | ||
const { Resend } = getModule('resend') | ||
const apiKey = | ||
|
This file was deleted.
Oops, something went wrong.