Skip to content

Commit

Permalink
test(sample-app): intent command for testing out mailers
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayak25 committed Nov 15, 2024
1 parent 7e57785 commit 4fcfbc3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
2 changes: 2 additions & 0 deletions integrations/sample-app/app/boot/sp/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { TestCacheConsoleCommand } from 'app/console/cache';
import { GreetingCommand } from 'app/console/greeting';
import { TestLogConsoleCommand } from 'app/console/log';
import { TestMailConsoleCommand } from 'app/console/mailer';
import { TestQueueConsoleCommand } from 'app/console/queue';
import { TestStorageConsoleCommand } from 'app/console/storage';

Expand All @@ -18,6 +19,7 @@ export class ConsoleServiceProvider extends ServiceProvider {
this.bind(TestStorageConsoleCommand);
this.bind(TestLogConsoleCommand);
this.bind(TestQueueConsoleCommand);
this.bind(TestMailConsoleCommand);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions integrations/sample-app/app/console/mailer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Command, ConsoleIO, log, Mail, MailMessage } from '@intentjs/core';

@Command('test:mail', { desc: 'Command to test the log' })
export class TestMailConsoleCommand {
async handle(_cli: ConsoleIO) {
log('Sending out email');
const mail3 = MailMessage.init()
.greeting('Hey there')
.line('We received your request to reset your account password.')
.button('Click here to reset your password', 'https://google.com')
.line('Alternative, you can also enter the code below when prompted')
.inlineCode('ABCD1234')
.line('Rise & Shine,')
.line('V')
.subject('Hey there from Intent');
await Mail.init().to('[email protected]').send(mail3);
return true;
}
}
12 changes: 5 additions & 7 deletions integrations/sample-app/config/mailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ export default registerNamespace(
* },
*/

/**
* resend: {
* provider: 'resend',
* apiKey: process.env.RESEND_API_KEY,
* from: process.env.FROM_ADDRESS,
* },
*/
resend: {
provider: 'resend',
apiKey: process.env.RESEND_API_KEY,
from: process.env.FROM_ADDRESS,
},
},

template: {
Expand Down
1 change: 1 addition & 0 deletions integrations/sample-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"objection": "^3.1.4",
"pg": "^8.13.1",
"reflect-metadata": "^0.2.0",
"resend": "^4.0.1-alpha.0",
"ulid": "^2.3.0",
"winston": "^3.14.2"
},
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/core/lib/mailer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class MailerService {
}

static async send(options: BaseProviderSendOptions, providerName?: string) {
const config = ConfigService.get('mailer');
const config = ConfigService.get('mailers');

providerName = providerName ?? config.default;
const providerConfig = config.channels[providerName];
const mailData = (await options.mail.getMailData()) as MailData;
Expand Down

0 comments on commit 4fcfbc3

Please sign in to comment.