1.3.0 • Published 9 months ago

@benhepburn/adonis-notifications-mail-channel v1.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

AdonisJS Notifications - Mail Channel

This package requires @benhepburn/adonis-notifications and @adonisjs/mail.

Install

Install peer dependencies @benhepburn/adonis-notifications and @adonisjs/mail, and then install this package from npm:

npm install @benhepburn/adonis-notifications-mail-channel

or

pnpm install @benhepburn/adonis-notifications-mail-channel

or

yarn add @benhepburn/adonis-notifications-mail-channel

Configuration

Configure @adonisjs/mail as required, then add the mail channel to config/notifications.ts.

import { MailChannel } from '@benhepburn/adonis-notifications-mail-channel';
...

const notificationsConfig = defineConfig({
  channels: {
    ...
    mail: MailChannel,
  },
});

Usage

Create a class-based or callback mail message as per the @adonisjs/mail docs. Then create a new file in app/notifications e.g. app/notifications/sign_up_notification.ts:

import { Notification } from '@benhepburn/adonis-notifications';
import { MailMessage, MailNotification } from '@benhepburn/adonis-notifications-aws-sns-channel/types';

export default class SignUpNotification extends Notification implements MailNotification {
  constructor() {
    super();
  }

  via(): string[] {
    return ['mail'];
  }

  toMail(): MailMessage {
    return {
      mail: new SignUpMail(),
      // OR
      mail: (message) => message.to(this.notifiable!.notificationGetEmail())...
      
      sendLater: true, // Optional; sends the mail queued instead of immediately
    };
  }
}
1.3.0

9 months ago

1.2.0

11 months ago

1.1.0

1 year ago