Core: Adonis api mail not working (adonis install @adonisjs/mail)

Created on 14 Dec 2017  路  5Comments  路  Source: adonisjs/core

Problem

Hi all, I am developing Adonis restful API services ( version 4.0). I am using adonis mail in my code. I have followed doc but I got an error like this : Cannot find module 'Adonis/Src/View'

Tools

Webstorm & insomina ( rest client )

My folder structure

structure

Sample Code

 config/Mail.js  - I am using mailtrap

 'use strict'

 const Env = use('Env')

 module.exports = {

 connection: Env.get('MAIL_CONNECTION', 'smtp'),
 smtp: {
 driver: 'smtp',
 pool: true,
 port: 2525,
 host: 'smtp.mailtrap.io',
 secure: false,
 auth: {
  user: "########",
  pass: "########"
},
maxConnections: 5,
maxMessages: 100,
rateLimit: 10
  },


sparkpost: {
  driver: 'sparkpost',
   apiKey: Env.get('SPARKPOST_API_KEY'),
   extras: {}
  }
   }

my Code : in user controller
 // Store the information

async store({request, response}) {

let validation = await  validate(request.all(), rules)
if (validation.fails()) {
  return response.status(400).json({data: 'error', message: validation._errorMessages[0].message, status: false})
}
const userInfo = request.all();
const users = new User();
users.username = userInfo.username;
users.email = userInfo.email;
users.password = userInfo.password;
let checkUser = await dataBase.table('users').where('email', '=', users.email)
if (checkUser.length > 0) {
  return response.status(400).json({data: 'insert fail', message: 'email already register', status: false})
}
await users.save();
// sending mail after registration
const data =request.only(['username','email', 'password']);
await Mail.send('emails.welcome', {}, (message) => {
  message.from('#####.com')
  message.to('####.com')
})
return response.status(201).json({message: 'user created successfull', status: true});

}

Screenshots - Rest client

error

Most helpful comment

Yes emails are stored in view templates, so you need to register the view provider inside the providers array

 '@adonisjs/framework/providers/ViewProvider'

All 5 comments

Yes emails are stored in view templates, so you need to register the view provider inside the providers array

 '@adonisjs/framework/providers/ViewProvider'

Thanks thetutlage Its working fine.

Should be added to docs, imo. Mail requires ViewProvider added or smth. (in mail section)

@outluch PRs are welcomed 馃

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

milosdakic picture milosdakic  路  3Comments

blendsoft picture blendsoft  路  3Comments

themodernpk picture themodernpk  路  3Comments

amrayoub picture amrayoub  路  4Comments

itsg2jakhmola picture itsg2jakhmola  路  3Comments