Skip to content

reg2005/adonis-mailbuilder

Repository files navigation

Table of contents

AdonisJS 5 mailbuilder

Adonis, mailbuilder, mailgen, livereloading

travis-image typescript-image npm-image license-image

How it works

  • Declarative creation of mails in classes (based on mailgen)
  • Livereload as CLI command (for quickly devloping your emails)
  • Mock data for tests (so that letters developed through livereload correspond to real letters that will go to the mail)
  • Naturally everywhere Typescript is used
  • CLI command to quickly create a Mailbuilder class based on the principle of "node ace make:model ModelName"

Installation

Install it:

npm i --save adonis-mailbuilder

Connect all dependences:

node ace configure adonis-mailbuilder

Create yor first mail

node ace mailbuilder:make AnyName

Start dev server

npm run dev

Go to url from cli like 'http://localhost:3333/mailbuilder'

Go to app/MailBuilder/AnyName.ts and change any options

Send your email

import MailBuilder from '@ioc:Adonis/Addons/MailBuilder'
import AnyName from 'App/MailBuilder/AnyName'
import Mail from '@ioc:Adonis/Addons/Mail'
import Env from '@ioc:Adonis/Core/Env'
export default class AuthController {
  public async register ({ auth, request, response }: HttpContextContract) {
    const { text, html } = await MailBuilder.render(
      new AnyName({ name: 'AnyName' })
    )
    await Mail.send(mail => {
        mail.subject('Thanks for registering')
        mail.text(text)
        mail.html(html)
        mail.to(ctx.session.email)
        mail.from(Env.get('MAIL_FROM') as string)
    })
  }
}

Docs for mailbuilder configuration

See docs