Giter Site home page Giter Site logo

mail's Introduction

@adonisjs/mail


gh-workflow-image npm-image license-image

Introduction

The AdonisJS Mail package is built on top of Nodemailer with support for queueing emails, better testing experience using fakes, and an extensive suite of officially maintained transports.

Official Documentation

The documentation is available on the AdonisJS website

Contributing

One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.

We encourage you to read the contribution guide before contributing to the framework.

Code of Conduct

In order to ensure that the AdonisJS community is welcoming to all, please review and abide by the Code of Conduct.

License

AdonisJS Mail is open-sourced software licensed under the MIT license.

mail's People

Contributors

ammezie avatar bitkidd avatar caiquecastro avatar cjpitch23 avatar dependabot[bot] avatar julien-r44 avatar kennymark avatar mastermunj avatar mcsneaky avatar ntvsx193 avatar romainlanz avatar stephenafamo avatar thetutlage avatar tibianmod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mail's Issues

SES driver issue

Added ses config option to mail.js configuration file, but got an error.
The file:

'use strict'

const Env = use('Env')

module.exports = {
  /*
  |--------------------------------------------------------------------------
  | Connection
  |--------------------------------------------------------------------------
  |
  | Connection to be used for sending emails. Each connection needs to
  | define a driver too.
  |
  */
  connection: Env.get('MAIL_CONNECTION', 'ses'),

  ses: {
    apiVersion: '2010-12-01',
    accessKeyId: Env.get('SES_KEY'),
    secretAccessKey: Env.get('SES_SECRET'),
    region: 'eu-west-1',
    rateLimit: 10
  }
}

Error:
E_MISSING_CONFIG: ses.driver is not defined inside config/mail.js file
Versions:
"@adonisjs/framework": "^4.0.15"
"@adonisjs/mail": "^3.0.1"

AdonisJS : Can't send email via @adonisjs/mail

I use adonis js version 4.1.0 and @adonisjs/mail version ^3.0.10. I'm not sure why. But I'm sure my email and password are correct which previously email can be used normally. Please help me. Thank for your solution. I got this error when I send email ExceptionHandler Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 136-20020a62188e000000b0050dc7628158sm4991712pfy.50 - gsmtp

my .env file

[email protected]
MAIL_PASSWORD=testpw
SMTP_HOST=smtp.gmail.com

and using

  const data = `<div>Testing</div>`;
  await Mail.raw(data, (message) => {
      message.to(getEmail.email);
      message
      .from(`${Env.get("MAIL_USERNAME")}`)
      .subject("Test Email Sending");
  });

In config/mail.js

connection: Env.get('MAIL_CONNECTION', 'smtp'),
smtp: {
    driver: 'smtp',
    pool: true,
    port: Env.get('SMTP_PORT', 465),
    host: Env.get('SMTP_HOST'),
    secure: true,
    auth: {
        user: Env.get('MAIL_USERNAME'),
        pass: Env.get('MAIL_PASSWORD')
    },
    maxConnections: 5,
    maxMessages: 100,
    rateLimit: 10
 },

In my package.json

{
     "name": "adonis-api-app",
     "version": "4.1.0",
     "adonis-version": "4.1.0",
     "description": "Adonisjs boilerplate for API server with pre-configured JWT",
     "main": " --inspect index.js",
     "scripts": {
         "start": "nodemon --inspect=0.0.0.0:3333 server.js",
          "test": "node ace test",
          "debug": "nodemon --inspect=0.0.0.0:3333 server.js",
          "migrate": "node database/script_migration/migrate_prevaa.js"
      },
     "keywords": [
         "adonisjs",
         "adonis-app"
      ],
     "author": "",
     "license": "UNLICENSED",
     "private": true,
     "dependencies": {
         "@adonisjs/ace": "^5.0.8",
         "@adonisjs/ally": "2.2.0",
         "@adonisjs/auth": "^3.0.7",
         "@adonisjs/bodyparser": "^2.0.9",
         "@adonisjs/cli": "^4.0.12",
         "@adonisjs/cors": "^1.0.7",
        "@adonisjs/drive": "^1.0.4",
        "@adonisjs/fold": "^4.0.9",
        "@adonisjs/framework": "^5.0.9",
        "@adonisjs/ignitor": "^2.0.8",
        "@adonisjs/lucid": "^6.2.0",
       "@adonisjs/lucid-slugify": "^1.0.3",
       "@adonisjs/mail": "^3.0.10",
       "@adonisjs/session": "^1.0.29",
       "@adonisjs/shield": "^1.0.8",
       "@adonisjs/validator": "^5.0.6",
       "adonis-lucid-polymorphic": "^1.0.1",
       "adonis-scheduler": "^3.0.2",
       "aws-sdk": "^2.788.0",
       "axios": "^0.21.0",
       "directory-tree": "^2.2.5",
       "faker": "^5.1.0",
       "html2json": "^1.0.2",
       "json-find": "^2.0.7",
       "lodash": "^4.17.21",
       "lucid-mongo": "^3.1.6",
       "mysql": "^2.18.1",
       "numeral": "^2.0.6",
       "sqlite3": "^5.0.0"
  },
 "devDependencies": {},
  "autoload": {
       "App": "./app"
  }
}

Cannot read property 'before' of undefined

Hi, I'm just trying to add new users to a mysql DB, which I thought it would be easy :), but I'm getting the error "Cannot read property 'before' of undefined". I have tried a lot of changes with no effect and i don't know what I'm doing wrong.
Please, could you help me?
Thanks in advance.

Package version

"adonis-version": "4.1.0"

Node.js and npm version

node: '13.3.0'
npm: '6.13.4',
Database mysql

UserController.js:

'use strict'

const User = use('../Models/User');

class UserController {
// authentication
async login({ request, auth }) {
const { email, password } = request.all();
const token = await auth.attempt(email, password);
return token;
}

// User create
async store({ request, response }) {
    const { name, username, email, addres, password } = request.all();
    const user = await User.create ({ name, username, email, addres, password });
    return user;
};

}

module.exports = UserController

User.js

'use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

/** @type {import('@adonisjs/framework/src/Hash')} */
const Hash = use('Hash')

class User extends Model {
static boot () {
super.boot()

/**
 * A hook to hash the user password before saving
 * it to the database.
 */
this.addHook('beforeSave', async (userInstance) => {
  if (userInstance.dirty.password) {
    userInstance.password = await Hash.make(userInstance.password)
  }
})

}

/**

  • A relationship on tokens is required for auth to
  • work. Since features like refreshTokens or
  • rememberToken will be saved inside the
  • tokens table.
  • @method tokens
  • @return {Object}
    */
    tokens () {
    return this.hasMany('App/Models/Token')
    }
    }

module.exports = User

And I'm using default @adonisjs/lucid/src/lucid/model

Thanks in advance again.

how can set email from with config

I use Zoho smtp and must set from in email how can set from in the config
this is my mail config

order: {
    driver: "smtp",
    service: "Zoho",
    host: "smtp.zoho.com",
    port: 465,
    secure: false,
    requireTLS: false,
    auth: {
      user: "orders@***.com",
      pass: **
    }
  },
 support: {
    driver: "smtp",
    service: "Zoho",
    host: "smtp.zoho.com",
    port: 465,
    secure: false,
    requireTLS: false,
    auth: {
      user: "support@***.com",
      pass: ***
    }
  }

and this my controller:

const user = await User.find(1);
    await Mail.connection("support").send(
      "emails.referal",
      { user: user.toJSON() },
      message => {
        message
          .to(user.email)
          .from("support@***.com")
          .subject("join cashineh now...");
      }
    );
    response.send("success");

I want to set messege.from() just one time in config is it possible?

Custom headers not sent when using nodemailer

Package version

7.2.5

Node.js and npm version

16.14.2
8.5.0

Sample Code (to reproduce the issue)

Mail headers do not get sent out if this isn't done.
I'm sure there is a more elegant way of doing this, but this is what got me going

/*

  • @adonisjs/mail
  • (c) Harminder Virk [email protected]
  • For the full copyright and license information, please view the LICENSE
  • file that was distributed with this source code.
    */

///

import nodemailer from 'nodemailer'
import {
MessageNode,
SmtpMailResponse,
SmtpDriverContract,
SmtpConfig,
} from '@IOC:Adonis/Addons/Mail'

/**

  • Smtp driver to send email using smtp
    */
    export class SmtpDriver implements SmtpDriverContract {
    private transporter: any

constructor(config: SmtpConfig) {
this.transporter = nodemailer.createTransport(config)
}

/**

  • Send message
    */
    public async send(message: MessageNode): Promise {
    if (!this.transporter) {
    throw new Error('Driver transport has been closed and cannot be used for sending emails')
    }
message.headers = this.convertHeadersToNodemailFormat(message.headers)

return this.transporter.sendMail(message)

}

/**

  • Close transporter connection, helpful when using connections pool
    */
    public async close() {
    this.transporter.close()
    this.transporter = null
    }

/**

  • nodemailer expects an object for headers, Adonis mailer uses an an array of objects
  • headers: [ { 'x-test': 'teststr' }, { 'x-test': '1234' } ] ===>
  • headers: { 'x-test': [ 'teststr', '1234' ] }
    */
    public convertHeadersToNodemailFormat(headers) {
    if (headers) {
    var newHeaders = {}
    for (var header of headers) {
    for (var headerKey in header) {
    if (!newHeaders[headerKey]) {
    newHeaders[headerKey] = []
    }
    if (header[headerKey] instanceof Array) {
    for (var headerListVal of header[headerKey]) {
    newHeaders[headerKey].push(headerListVal)
    }
    } else {
    newHeaders[headerKey].push(header[headerKey])
    }
    }
    }
    return newHeaders
    }
    return headers
    }
    }

BONUS (a sample repo to reproduce the issue)

https://github.com/rmmlopes/mail

Edge: "LabeledStatement" is not supported

I'm using edge to create template for sending email.
But I faced a error with Edge
My code example:

return Mail.send((message) => {
        message
          .embed(Application.tmpPath('/images/bg.png'), 'bg')
          .from('[email protected]')
          .to(email)
<div style="background-image: url({{cid:bg}}); padding: 0px 64px 20px 64px ;width: 700px; height: 1200px; margin: 0 auto;  background-repeat: no-repeat; object-fit: contain">

then I faced an error:

status: 'rejected',
reason: EdgeError: "LabeledStatement" is not supported

Have any suggestions for me. Thanks a lot

Mail connection stays open => ace commands don't stop

I send mails from an ace command via SMTP. The ace command doesn't close (which is bad because it's intended to run via cron) because this package opens a SMTP connection but never closes it.
We need either a Mail.close() command (similar to this) or the connection should be closed by default. I could fix the issue by adding this.transporter.close() within src/Mail/Drivers/Smtp.js, but I think there should be a better solution for this.

Package version

3.0.9

Node.js and npm version

Node 12.2.0
npm 6.9.0

Sample Code (to reproduce the issue)

Just create a fresh package + an ace command, send any mail via smtp from there.

Cannot read property 'body' of undefined

TypeError: Cannot read property 'body' of undefined
at Request.post (/Users/mac/NickelIT/Projects/Adonis/project-aviscan/node_modules/@adonisjs/mail/src/Request/index.js:98:31)

Add possibility to get status of mail

Why this feature is required (specific use-cases will be appreciated)?

To keep a log of important mails its important to know that the mail was accepted by the mailer (like SMTP).
Callback function in case of success or failure would be appreciated.

Have you tried any other work arounds?

try/catch surrounding Mail.sendLater does not work as intended

Are you willing to work on it with little guidance?

Surely

configuration amazon ses

in my application I need to use email sending, it was decided to use amazon ses, but in the default settings in mail.js, inside the config folder, there is no example of how to configure amazon ses, someone could send me the configuration code snippet for amazon ses

Error: Cannot find module '@adonisjs/mail/build/config' with Docker

Problem

Note I follow all steps from https://docs.adonisjs.com/cookbooks/dockerizing-adonis

I'm dockerizing my adonisjs app but when I try to docker compose up I have an error about this line in config/mail.ts.

import { mailConfig } from '@adonisjs/mail/build/config'

This is the error that gave me.

โžœ  treninoo-api git:(main) docker compose up
[+] Running 1/0
 โ ฟ Container treninoo-api  Created                                                                                                                               0.0s
Attaching to treninoo-api
treninoo-api  | [ info ]  building project...
treninoo-api  | [ info ]  starting http server...
treninoo-api  | Debugger listening on ws://0.0.0.0:9229/31d3cc7f-6bc1-452b-a8c1-6474108fd871
treninoo-api  | For help, see: https://nodejs.org/en/docs/inspector
treninoo-api  | 
treninoo-api  | Error: Cannot find module '@adonisjs/mail/build/config'
treninoo-api  | Require stack:
treninoo-api  | - /home/node/app/config/mail.ts
treninoo-api  | - /home/node/app/node_modules/require-all/index.js
treninoo-api  | - /home/node/app/node_modules/@poppinss/utils/build/src/Helpers/requireAll.js
treninoo-api  | - /home/node/app/node_modules/@poppinss/utils/build/src/Helpers/index.js
treninoo-api  | - /home/node/app/node_modules/@poppinss/utils/build/helpers.js
treninoo-api  | - /home/node/app/node_modules/@adonisjs/fold/build/src/Ioc/index.js
treninoo-api  | - /home/node/app/node_modules/@adonisjs/fold/build/index.js
treninoo-api  | - /home/node/app/node_modules/@adonisjs/application/build/index.js
treninoo-api  | - /home/node/app/node_modules/@adonisjs/assembler/build/src/requireHook/ioc-transformer.js
treninoo-api  | - /home/node/app/node_modules/@poppinss/utils/build/src/esmRequire.js
treninoo-api  | - /home/node/app/node_modules/@poppinss/utils/build/index.js
treninoo-api  | - /home/node/app/node_modules/@adonisjs/require-ts/build/src/Compiler/index.js
treninoo-api  | - /home/node/app/node_modules/@adonisjs/require-ts/build/index.js
treninoo-api  | - /home/node/app/node_modules/@adonisjs/assembler/build/src/requireHook/index.js
treninoo-api  | - /home/node/app/node_modules/@adonisjs/assembler/build/register.js
treninoo-api  | - internal/preload
treninoo-api  | 
treninoo-api  | at /home/node/app/config/mail.ts(anonymous):9
treninoo-api  | 4    * Feel free to let us know via PR, if you find something broken in this contract
treninoo-api  | 5    * file.
treninoo-api  | 6    */
treninoo-api  | 7   
treninoo-api  | 8   import Env from '@ioc:Adonis/Core/Env'
treninoo-api  | 9   import { mailConfig } from '@adonisjs/mail/build/config'
treninoo-api  | 10  
treninoo-api  | 11  export default mailConfig({
treninoo-api  | 12    /*
treninoo-api  | 13    |--------------------------------------------------------------------------
treninoo-api  | 14    | Default mailer
treninoo-api  | 
treninoo-api  | 1 Module._compile
treninoo-api  |   /home/node/app/node_modules/pirates/lib/index.js:99
treninoo-api  | 
treninoo-api  | 2 Object.newLoader [as .ts]
treninoo-api  |   /home/node/app/node_modules/pirates/lib/index.js:104
treninoo-api  | 
treninoo-api  | [ warn ]  Underlying HTTP server died with "0 code"
treninoo-api  | [ info ]  watching file system for changes

BONUS (a sample repo to reproduce the issue)

This is the project I am developing, hope it can help.

https://github.com/c0c4i/treninoo-api

Use the Mail API with HTML without edge views

I have an application where the user writes the mail content in a HTML editor, currenty in Adonis i cannot find a way to send an email with an HTML String so i have to use the aws-sdk directly. I would like yo have a way to use the Mail API

Feature: Ethereal transporter

Would be nice to get support for Ethereal transporter.

The key things are:

    return nodemailer.createTestAccount()
      .then((account) => {
        log.debug('Ethereal account created:', account)

        transporter = nodemailer.createTransport({
          host: 'smtp.ethereal.email',
          port: 587,
          secure: false,
          auth: {
            user: account.user,
            pass: account.pass
          }
        })

        return transporter
      })

Then later when email gets sent:

const url = nodemailer.getTestMessageUrl(info)
Logger.info('Email URL: %s', url)

Of course, optionally, instead of creating a new account, can let user set an account in config as well. But Ethereal has this feature so you can create accounts on the fly.

But maybe could be a helper that creates an account and updates the config.

Can't send email to multiple recipients.

Can't send email to multiple recipients.

I tried to send email to multiple recipients by using Mail.sendLater But i got an error like below picture.
Screenshot 2566-06-16 at 10 59 51

Could you please help me to solve this issue.

Thank you.

Package version

  • "@adonisjs/mail": "^8.1.2"

Node.js and npm version

  • node --version v20.0.0
  • pnpm -v 8.6.2

Sample Code (to reproduce the issue)

const mails :string = '[email protected], [email protected]'      
await Mail.sendLater((message) => {
          message
            .from('[email protected]')
            .to(mails)
            .subject(`${data.type}`)
            .htmlView('emails/template', {
              alarm: data.type,
              site_name: data.site_name,
              device_no: data.device_id,
              timestamp: moment().format('DD MM YYYY hh:mm:ss'),
            })
          })

Unexpected token '.' on SES

I can't send email with SES Amazon

Package version

"@adonisjs/ace": "^11.0.1",
"@adonisjs/assembler": "^3.0.0",
"@adonisjs/auth": "^5.1.1",
"@adonisjs/core": "~5.0.4-preview-rc",
"@adonisjs/lucid": "^10.0.0",
"@adonisjs/mail": "^7.1.1",
"@adonisjs/repl": "^1.0.0",
"@adonisjs/session": "^4.0.6",
"@adonisjs/view": "^3.0.0",

Node.js and npm version

  • Node.js - v12.18.3
  • Yarn - v1.22.5

Sample Code (to reproduce the issue)

import Mail from '@ioc:Adonis/Addons/Mail'
import Env from '@ioc:Adonis/Core/Env'

import { DateTime } from 'luxon'

export default class MailerService {
  async sendMail(
    user: { name: string; email: string },
    event: { startTime: DateTime; url: string; password: string }
  ) {
    await Mail.use('ses').send((message) => {
      message
        .from(Env.get('SES_EMAIL_FROM') as string)
        .to(user.email)
        .subject('Success')
        .text('here')
    })
  }
}

Console Output

Unexpected token '.'
[1]    .../node_modules/@adonisjs/mail/build/src/Helpers/prettyPrint.js:70
[1]         output += `\n${colors.dim('โ”‚')}  ${colors.dim('from:')} ${mail.message.from?.address}`;
[1]                                                                                     ^
[1]     
[1]     SyntaxError: Unexpected token '.'
[1]         at compileFunction (<anonymous>)
[1]         at wrapSafe (internal/modules/cjs/loader.js:1053:16)
[1]         at Module._compile (internal/modules/cjs/loader.js:1101:27)
[1]         at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
[1]         at Module.load (internal/modules/cjs/loader.js:985:32)
[1]         at Function.Module._load (internal/modules/cjs/loader.js:878:14)
[1]         at Module.require (internal/modules/cjs/loader.js:1025:19)
[1]         at require (internal/modules/cjs/helpers.js:72:18)
[1]         at Object.<anonymous> (.../node_modules/@adonisjs/mail/build/src/Mail/MailManager.js:22:23)
[1]         at Module._compile (internal/modules/cjs/loader.js:1137:30)
[1] {
[1]   error: .../node_modules/@adonisjs/mail/build/src/Helpers/prettyPrint.js:70
[1]       output += `\n${colors.dim('โ”‚')}  ${colors.dim('from:')} ${mail.message.from?.address}`;
[1]                                                                                   ^
[1]   
[1]   SyntaxError: Unexpected token '.'
[1]       at compileFunction (<anonymous>)
[1]       at wrapSafe (internal/modules/cjs/loader.js:1053:16)
[1]       at Module._compile (internal/modules/cjs/loader.js:1101:27)
[1]       at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
[1]       at Module.load (internal/modules/cjs/loader.js:985:32)
[1]       at Function.Module._load (internal/modules/cjs/loader.js:878:14)
[1]       at Module.require (internal/modules/cjs/loader.js:1025:19)
[1]       at require (internal/modules/cjs/helpers.js:72:18)
[1]       at Object.<anonymous> (.../node_modules/@adonisjs/mail/build/src/Mail/MailManager.js:22:23)
[1]       at Module._compile (internal/modules/cjs/loader.js:1137:30)

Migrate the AWS SDK to V3

Why this feature is required (specific use-cases will be appreciated)?

With V3 of the AWS SDK it was possible to modularize the modules, thus providing a smaller build size and really only having what is needed. When looking at the code superficially, the implementation would not be very complex, there would only be some paradigm shifts in the issue of credentials.

Have you tried any other work arounds?

Yes, but I believe that this change would bring many benefits to the users of this package.

Are you willing to work on it with little guidance?

Surely

error when installing @adonisjs/mail

Hi, i want send email with my adonis app, and then i install adonis mail in my app ( adonis install @adonisjs/mail ),
and then register provider in my start/app.js but when i try to run adonis serve, it throwing error Error: Cannot find module '@adonisjs/mail/providers/MailProvider'.

can some one help me? thank you

Version

Adonis = 4.1.0
@adonisjs/mail = 7.1.0
npm = 6.11.3
node = 12.10.0

start/app.js

'use strict'

const providers = [
  '@adonisjs/framework/providers/AppProvider',
  '@adonisjs/auth/providers/AuthProvider',
  '@adonisjs/bodyparser/providers/BodyParserProvider',
  '@adonisjs/cors/providers/CorsProvider',
  '@adonisjs/lucid/providers/LucidProvider',
  '@adonisjs/session/providers/SessionProvider',
  '@adonisjs/mail/providers/MailProvider'
]

const aceProviders = [
  '@adonisjs/lucid/providers/MigrationsProvider'
]

const aliases = {}

const commands = []

module.exports = { providers, aceProviders, aliases, commands }

Not work method .send()

From gitter chat:

Installed the new @adonisjs/mail provider, and for some sort of reason got Cannot find module 'Mail', then added to aliases Adonis/Addons/Mail, and again no luck, when I try to send something it drops Mail.send is not a function

In doc https://github.com/adonisjs/adonis-mail/blob/develop/instructions.md example use Mail.send, but it's not worked.
I use this for bypass problem:

const sender = await Mail.connection()
await sender.send('welcome', {
  user: user
}, (message) => {
  message.from('[email protected]')
  message.to(user.email, user.name)
  message.subject('Test, Hello world!')
})

Build is failing: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

Prerequisites

The build process is throwing this error:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb12b40 node::Abort() [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 2: 0xa2fe25 node::FatalError(char const*, char const*) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 3: 0xcf946e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 4: 0xcf97e7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 5: 0xee3875  [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 6: 0xee43bc  [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 7: 0xef22f1 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 8: 0xef584c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 9: 0xec1dfb v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
10: 0x122adbb v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
11: 0x160c599  [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
Aborted (core dumped)

I think it is happening because we are importing the whole AWS SDK here:

import * as aws from 'aws-sdk'

I think it can be fixed by importing the necessary code only.
For reference: aws/aws-sdk-js#2683 (comment)

Package version

7.1.1

Node.js and npm version

v16.1.0 and 0.35.1

Build is failing: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

The build process is throwing this error:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb12b40 node::Abort() [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 2: 0xa2fe25 node::FatalError(char const*, char const*) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 3: 0xcf946e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 4: 0xcf97e7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 5: 0xee3875  [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 6: 0xee43bc  [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 7: 0xef22f1 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 8: 0xef584c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
 9: 0xec1dfb v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
10: 0x122adbb v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
11: 0x160c599  [/home/ubuntu/.nvm/versions/node/v16.1.0/bin/node]
Aborted (core dumped)

I think it is happening because we are importing the whole AWS SDK here:

import * as aws from 'aws-sdk'

I think it can be fixed by importing the necessary code only.
For reference: aws/aws-sdk-js#2683 (comment)

Package version

7.1.1

Node.js and npm version

v16.1.0 and 0.35.1

Mail is not sent from an Ace command

Package version

5.2.3

Node.js and npm version

Node.js: v14.16.1
Npm: 6.14.12

Sample Code (to reproduce the issue)

import { BaseCommand } from '@adonisjs/core/build/standalone'
import Mail from '@ioc:Adonis/Addons/Mail'

export default class SendMail extends BaseCommand {

	/**
	 * Command Name is used to run the command
	 */
  public static commandName = 'send:mail'

	/**
	 * Command Name is displayed in the "help" output
	 */
  public static description = ''

  public static settings = {
    loadApp: true,
  }

  public async run () {
    this.logger.info('Hello world!')
    await Mail.sendLater((message) => {
     try {
          await Mail.sendLater((message) => {
            message
              .from('[email protected]')
              .to('[email protected]')
              .subject('Votre offre arrive ร  expiration : ')
              .text('Hello World')
          })
        } catch(error) {
          console.log(error)
        }
  }
}

Error: Cannot find module './Drivers'

This is a strange one. So if I run npm install adonis-mail-provider@latest and then cd node_modules/adonis-mail-provider/src/Mail I see the directory drivers instead of Drivers. All the other directories look fine except that one.

I know the repo shows everything correct. I tried clear the npm cache and clearing the node_modules directory. Any tips on what else I could try to fix this?

BCC and CC recipients with Mailgun driver not being sent mail.

I believe there is a bug with @adonisjs/mail package when it comes to sending bcc and/or cc recipients on a Mailgun driver. Since MIME only sends to the recipients in the to key, it doesn't send the email to those in the cc or bcc keys. I tried adding the recipients to both to and bcc and it sent the mail appropriately but the bcc recipients were not hidden. Looking into the code in the underlying Mail driver, I was able to fix the issue by updating the send() function in Mailgun.js with the following code

           Object.keys(recipients).forEach((key) => {
            if (key !== 'to') form.append('to', recipients[key])
            form.append(key, recipients[key])
        });

Here whenever the recipients are added to the form, it will append the bcc and cc recipients to the form as well.

After testing it, I was able to send emails to all of the recipients and the bcc recipients were hidden as intended.

Package version

@adonisjs/mail: 7.2.1

Node.js and npm version

Node: v14.17.0
NPM: v7.13.0

Sample Code (to reproduce the issue)

  messsage
    .from('[email protected]')
    .to('[email protected]')
    .bcc('[email protected]')
    .subject('This is just a test')
    .htmlView('emails/test');

Adonisjs v5 EmailTransportException: connect ECONNREFUSED 127.0.0.1:443

Package version

Adonisjs v5

  • "@adonisjs/ace": "^6.9.3"
  • "@adonisjs/auth": "^4.3.0"
  • "@adonisjs/core": "^5.0.0-preview-rc-1.11"
  • "@adonisjs/fold": "^6.4.0"
  • "@adonisjs/lucid": "^8.3.1"
  • "@adonisjs/mail": "^4.2.2"
  • "@adonisjs/view": "^2.0.7"

Node.js and npm version

  • node v12.18.1
  • npm v6.14.5

Sample Code (to reproduce the issue)

Basically I've just copied from docs

await Mail.send((message) => {
          message
            .from('[email protected]')
            .to('[email protected]')
            .subject('Email address verification')
            .htmlView('emails/verification', data)
        })

When I try to send message I've got this error:

EmailTransportException: connect ECONNREFUSED 127.0.0.1:443
    at Function.apiFailure (/Users/mac-user/projects/api/node_modules/@adonisjs/mail/build/src/Exceptions/EmailTransportException.js:27:16)
    at MailgunTransport.send (/Users/mac-user/projects/api/node_modules/@adonisjs/mail/build/src/Transports/Mailgun.js:124:72)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  response: {}
}

ses driver issue in @adonisjs/mail:4.1.1

I found it difficult to understand how to use SES with this package. I am getting "MODULE_NOT_FOUND" error

Package version

"@adonisjs/mail": "^4.1.1",

Node.js and npm version

Node 14.5.0

Sample Code (to reproduce the issue)

Mail.send(message => {
          message
            .to(data.email)
            .from('[email protected]')
            .htmlView('registration_confirmation_email.edge', {
              token: user.confirmation_token,
              userName: user.name,
              appURL: Env.get('APP_URL', 'localhost:3333'),
            })
        })

I am using following Config file

   ses: {
      driver: 'ses',
      apiVersion: '2010-12-01',
      key: Env.get('SES_ACCESS_KEY') as string,
      secret: Env.get('SES_ACCESS_SECRET') as string,
      region: Env.get('SES_REGION') as string,
      sslEnabled: true,
      sendingRate: 10,
      maxConnections: 5,
    },

Edge dot folder notation is breaking plain/text support(?)

Hi @thetutlage,

I found a problem while using Edge and plain/text mail.

I have this structure:

| - views
| --- emails
| ----- edge
| ------- welcome.edge
| ----- plain
| ------- welcome.text

This structure is not possible because when sending the mail I use it like this (as described in the documentation, with the .text prefix):

await Mails.send(['emails.edge.welcome', 'emails.plain.welcome.text'])

The dot-notation folder use the .text as a new nested level.
I did it works with welcome-text.edge but this is not really beautiful...

I don't know if it is a bug or an expected behaviour...
What is you opinion on this?

Thanks! ๐Ÿ™‚

MAIL_CONNECTION doesn't fetch driver

Thanks for all of the amazing work on Adonis. Love it!

I was trying to get adonis-mail installed, and I ran into some issues in finding a driver. I am wondering if maybe there is something wrong with how MAIL_CONNECTION fetches the driver from the config.

My .env

MAIL_CONNECTION=ses
SES_KEY=ABCD
SES_SECRET=12345
SES_REGION=us-west-2

My mail.config

{
  connection: Env.get('MAIL_CONNECTION', 'smtp'),

  ses: {
    driver: 'ses',
    apiVersion: '2010-12-01',
    accessKeyId: process.env.SES_KEY,
    secretAccessKey: process.env.SES_SECRET,
    region: process.env.SES_REGION,
  }

}

As far as I can tell from the docs and the source code, setting the connection should tell adonis-mail to check for a config key called ses and then it should find the ses.driver from the object. However, when I try to send mail with this configuration, I get a E_INVALID_MAIL_DRIVER error.

I have discovered that if I set a driver: 'ses' directly into my mail.config, then things work smoothly. Is this a bug, or am I missing something? It seems redundant to specify the driver in two places.

My WORKING mail.config
My mail.config

{
  driver: 'ses',
  connection: Env.get('MAIL_CONNECTION', 'smtp'),

  ses: {
    driver: 'ses',
    apiVersion: '2010-12-01',
    accessKeyId: process.env.SES_KEY,
    secretAccessKey: process.env.SES_SECRET,
    region: process.env.SES_REGION,
  }

}

Thanks!

Mailgun regions un-released

Hi,

It seems you have merged a feature into develop to support Mailgun regions but this has not been released to NPM.

Could you please release this on NPM thanks.

Not template folder included, problem with provider

Tried to install @adonisjs/mail@alpha package and got several issues.
The first one is that no template folder in build directory, so node ace invoke cannot proceed.
The second is somehow related to provider itself:

Error: Make sure export default the provider from /node_modules/@adonisjs/mail/build/providers/MailProvider.js

Package version

4.0.0 or alpha

Node.js and npm version

12.16.3
6.14.4

Sample Code (to reproduce the issue)

None

BONUS (a sample repo to reproduce the issue)

Just get @adonisjs/mail@alpha

Does this support Adonis 4.1?

I'm not sure this is an issue, maybe this lib is only for the new Adonis.
I am willing to help develop a solution if necessary.

I followed these instructions and when I try to run my app or simply type adonis in the terminal it throws:

Error: Cannot find module '@adonisjs/mail/providers/MailProvider'
Require stack:
- /home/xxx/workspace/xxx/api/node_modules/require-stack/src/index.js
- /home/xxx/workspace/xxx/api/node_modules/require-stack/index.js
- /home/xxx/workspace/xxx/api/node_modules/@adonisjs/fold/src/Ioc/index.js
- /home/xxx/workspace/xxx/api/node_modules/@adonisjs/fold/index.js
- /home/xxx/workspace/xxx/api/ace
- /home/xxx/.nvm/versions/node/v14.16.0/lib/node_modules/@adonisjs/cli/index.js

(For security reasons I replaced name and company name by xxx)

I noticed it looks different compared to other plugins, it has a build folder with ts files, I was able to get it to work with version 3.0.9 but it doesn't support SES, so for now I replaced it by a custom implementation of nodemailer.

Package version

Adonis 4.1
Adonis CLI 4.0.12
@adonisjs/mail 7.0.0 (Latest)

Node.js and npm version

$ node --version
v14.16.0
$ npm --version
6.14.11

Sample Code (to reproduce the issue)

$ adonis install @adonisjs/mail

start/app.js

const providers = [
  ...
  '@adonisjs/mail/providers/MailProvider',
]

Thanks in advance โค๏ธ

How to get the mail sending result

I need to know if an email has sent or has bounce.
But in my tests the adonis mail response is always the same, for a valid or invalid email.

E_MISSING_CONFIG: ses is not defined

I found it difficult to understand how to use SES with this package. I don't know if I'm doing it correctly, because the documentation was not very specific with this driver.

Package version

"@adonisjs/mail": "^3.0.9",

Node.js and npm version

Node 12

Sample Code (to reproduce the issue)

.env
MAIL_CONNECTION=ses

  await Mail.send(
    'emails.welcome',
    { user: user.toJSON(), tokenQueryString },
     (message) => {
       message
        .to(user.email)
        .from('noreply@')
        .subject('Ative sua conta')
     })

[Feature] Add ability to use markdown templates

Laravel gives us the ability to have blade templates that take blade/markdown and turn it into an HTML email template. This saves some major headache when it comes to making emails beautiful and responsive. It would be awesome if Adonis had the same functionality.

Proposal

Add a markdown method to the Mailer and some built in components that get added to edge templates. Developers should ideally be able to use the markdown method to render an edge template, or send plain markdown which will be parsed into valid email HTML before being sent.

Example Code

<!-- resources/views/emails/shipped.edge -->

@component('mail.message')
# Order Shipped

Your order has been shipped!

@component('mail.button', url = {{ order.viewUrl }})
View Order
@endcomponent

Thanks,<br>
{{ Config('appName') }}
@endcomponent
// app/Controllers/Http/OrdersController.js

await Mail.markdown('emails.shipped', Order.toJSON(), (message) => {
  message.subject('Hello ...')
  message.from('[email protected]')
  message.to('[email protected]')
})

Reference

https://laravel.com/docs/5.5/mail#markdown-mailables
https://www.npmjs.com/package/markdown
https://www.npmjs.com/package/markdown-it

No Mail support in adonis v5.

Lack of documentation

There is no clear documentation for how to set up Mail in Adonis js V5.
Blow the command is not doing anything but updating ace-manifest.json only

 node ace invoke @adonisjs/mail  

No config file is there for mail as well.

SendGrid driver

I'm very impressed with the framework and would like to thank @thetutlage and the others for the great job!

However, there is still a small detail missing โ€” SendGrid driver for the mail so I think it deserves a separate issue.

P. S. See PR with the deprecated implementation #1

[MailGun] GotError: options.body must be a ReadableStream, string or Buffer

adonis-mail version: git#develop
Driver used: mailgun
Node.js version: v6.4.0
npm version: v3.10.3

Hey !

I got an error from got when I try to send a email with the mailgun driver.

Exception

{ GotError: options.body must be a ReadableStream, string or Buffer
    at got (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/got/index.js:81:10)
    at Function.got.(anonymous function) [as post] (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/got/index.js:272:10)
    at MailGunTransport.send (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/adonis-mail-provider/src/Mail/Drivers/MailGun/transport.js:75:9)
    at Nodemailer.<anonymous> (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/nodemailer/lib/nodemailer.js:324:30)
    at Nodemailer._processPlugins (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/nodemailer/lib/nodemailer.js:352:16)
    at Nodemailer.<anonymous> (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/nodemailer/lib/nodemailer.js:318:14)
    at Nodemailer._processPlugins (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/nodemailer/lib/nodemailer.js:352:16)
    at Nodemailer.sendMail (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/nodemailer/lib/nodemailer.js:280:10)
    at MailGun.send (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/adonis-mail-provider/src/Mail/Drivers/BaseDriver.js:60:22)
    at Mail.send (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/adonis-mail-provider/src/Mail/Mail.js:129:30)
    at next (native)
    at onFulfilled (/Users/romainlanz/workspace/qualitas-helvetica.ch/node_modules/co/index.js:65:19)
    at process._tickDomainCallback (internal/process/next_tick.js:129:7) nested: undefined, status: 500 }

The error seems to be thrown when we are calling got.post(...) on the MailGun API. It's at the line 75 of the MailGun driver

Cannot read property 'body' of undefined

Package version

addonis 4.1.0

Node.js and npm version

node v10.16.3
npm 6.9.0

#Mailgun
MAILGUN_DOMAIN="sandboxaXXXXXXXFAKEXXXXXXXXXXX.mailgun.org"
MAILGUN_API_REGION="US"
MAILGUN_API_KEY="XXXXXXXXXXXXXXXXFAKEXXXXXXXXXXXXXXX"

Sample Code (to reproduce the issue)

await Mail.raw('<h1> HTML email </h1>', (message) => { message.from('[email protected]') message.to('[email protected]') })

Sample Code 2

`const data = request.only(['email', 'username', 'password'])
const user = await User.create(data)

await Mail.send('emails.welcome', user.toJSON(), (message) => {
  message
    .to(user.email)
    .from('<from-email>')
    .subject('Welcome to yardstick')
})`

ERROR MESSAGE

{"error":{"message":"Cannot read property 'body' of undefined","name":"TypeError","status":500,"frames":[{"file":"node_modules\\@adonisjs\\mail\\src\\Request\\index.js","filePath":"E:\\Desarrollos\\WeProtectAll\\code\\wpaccds-rest-api\\node_modules\\@adonisjs\\mail\\src\\Request\\index.js","method":"Request.post","line":98,"column":31,"context":{"start":93,"pre":" auth: this._basicAuth\n })\n return response.body\n } catch ({ response, message }) {\n const error = new Error(message)","line":" error.errors = response.body","post":" throw error\n }\n }\n}\n"},"isModule":true,"isNative":false,"isApp":false},{"file":"internal/process/next_tick.js","filePath":"internal/process/next_tick.js","method":"process._tickCallback","line":68,"column":7,"context":{},"isModule":false,"isNative":true,"isApp":false}]}}

I can't send mail on the server

Hello,

While working in the local, it doesn't work on the server.

Error: Invalid login: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtk 534-5.7.14 6YQOu2fx37epuJLJai4mSzLHzfrw87hFpUhNlcO6SgDJbubtLDDLORz17ibOi44w4MqmWm 534-5.7.14 cHamy1B54_C2p_L9KL0uhcu7dowd7e3pTYVA6I9CzIHIxybI2tAVGhufoulYLNITWkgMm0 534-5.7.14 wyNiTiewf-Fvwgq1yG4sCjnB3JTPatPyGucXv3ifCbOUBHpEIJu2OsA9usvoeMbNc1WKfe 534-5.7.14 cb8cfDAye4qb36vsEgHOKYdXt9BDc> Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 c18sm13481146wmd.13 - gsmtp
How can I solve this?

Regards.

Set email header in adonis 4

Hi,

I cannot add an email header in config, neither in code.
In Adonis 3.2 it was possible by calling message.header(key, value)
Has this feature been removed or is it possible to do it in another way?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.