[v4] How to create a new Maildriver?


#1

i try it like in version 3 http://adonisjs.com/docs/3.2/mail#_adding_new_drivers
but i have no luck.

Can someone give me a smal example how to do this?
Is in v4 also a Log-driver for Mail testing?

thanks in advance.


#2

okay i think i got a solution for my problemā€¦ at the moment i get the mail on the consoleā€¦
i forgett to register the driver:
now hier my final (at the moment) files

extend.js

const {ioc} = require('@adonisjs/fold')
const Log = require('../providers/Log')

ioc.extend('Adonis/Addons/Mail', 'log', function (app) {
  const config = app.use('Adonis/Src/Config')
  return new Log(config)
})

provider/Log.js

'use strict'

class Log {
  
  setConfig (config) {
    this.toPath = config.toPath
    this.name = 'log-driver'
    this.version = '0.0.1'
  }

  
  send (message, callback) {
    console.log(message)
  }

}
module.exports = Log

cofig/mail.js

'use strict'

const Env = use('Env')

module.exports = {
  
  connection: Env.get('MAIL_DRIVER', 'log'),

  log: {
    driver: 'log',
    toPath: Helpers.tmpPath('logs/mail.eml')
  }
}