Git Product home page Git Product logo

mailer's People

Contributors

0x1a4 avatar alexandret-devid avatar alexhutsau avatar amitailanciano avatar aoor9 avatar bioruebe avatar cdiaz avatar dependabot[bot] avatar dmitry-zaets avatar eduardoleal avatar frezyn avatar juandav avatar leosuncin avatar maclemented avatar morpheus-87 avatar nelsonblack avatar nmonin-spro avatar otonielguajardo avatar pawpartyka avatar peterkracik avatar rafaelbatistamarcilio avatar reinaldooli avatar renovate-bot avatar rnkdsh avatar sdgoij avatar shanerich5 avatar simonrosenau avatar stephenwade avatar x51xxx avatar yanarp 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  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailer's Issues

Got an error when try to send email without use of any template engine

Tried to send email just without any template engine like in your example:

this.mailerProvider.sendMail({
  to: '[email protected]', // sender address
  from: '[email protected]', // list of receivers
  subject: 'Testing Nest MailerModule โœ”', // Subject line
  text: 'welcome', // plaintext body
  html: '<b>welcome</b>' // HTML body content
})

I got the following:
UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined.

The error came from this function(mailer.provider.ts:63):

private getTemplatePath(templateDir: string, templateName?: string, extension?: string) {
    return path.join(process.cwd(), templateDir || './public/templates', templateName) + extension;
  }

There is no default value for the templateName variable and in this case the path got undefined argument, which caused the above error.
I was set a dummy empty template file path to sendMail's argument and it's solved the issue, but in this case I must have to put a file path and create an empty file.

Problem with typings?

Hi, I tried to follow the readme and seems like there's a problem with typings because VSCode can't find and import interfaces..

image

Or maybe the latest version wasn't published, could you please check it?

configuration, templateDir cannot resolve path with node path.resolve

Not sure if this is something I am doing wrong, but I observed when I try to use path.resolve to resolve the template directory path. the following error is thrown

UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open '/home/user/Files/project/home/user/project/src/app/welcome/index.pug'

Implementation example:

.....
import { resolve } from 'path';

@module({
....
imports: [
MailerModule.forRoot({
...,
templateDir: resolve('views/email-templates/')
})
]
})

The reason why I am trying to use path.resolve is that I am planning to bundle the package with webpack and the paths will change.

logging and debugging

im just curious if i possible to add logging and debugging? Similar implementation on this link,
Debugging

from .env file / bash.

export EMAIL_TRANSPORT="smtps://username:[email protected]/?pool=true"
export EMAIL_FROM="<email_sender_here>"

current code;

@Module({
  imports: [
    MailerModule.forRoot({
      transport: EMAIL_TRANSPORT,
      defaults: { from: EMAIL_FROM },
      template: {
        dir,
        adapter: new HandlebarsAdapter(),
        options: { strict: true },
      },
    }),
  ],
})
export class EmailsModule {}

Im thinking that maybe that possible if we create a "transport" and replace "EMAIL_TRANSPORT",

Suggested implementation

import * as nodemailer form 'nodemailer';

let customTransporter = nodemailer.createTransport(options[, defaults]);

@Module({
  imports: [
    MailerModule.forRoot({
      transporter: customTransporter, // to override the transport
      defaults: { from: EMAIL_FROM },
      template: {
        dir,
        adapter: new HandlebarsAdapter(),
        options: { strict: true },
      },
    }),
  ],
})

i think not possible to have custom transport, due to this
transporter implementation
unless i have to extend the mailService, create a setter method to "override" the transporter property.

But i dont know how to do it :(

Do you have any suggestions or alternative implementations?

sendMail options errors

I believe the latest version, have somewhat didn't included the sendMail configuration in the send-mail-options-interface.ts

How to configure custom transport ?

with nodemailer:

return nodemailer.createTransport(
                    ses({
                        accessKeyId: 'xxxx',
                        secretAccessKey: 'xxxx',
                        region: 'eu-west-1'
                    })
                )
                .sendMail(mailOptions, function (err: Error, info: any) {
                    if (err) {
                        //return reject('Error send email, please contact administrator to best support.');
                        throw err;
                    }
                    console.log('mail sent');
                    return resolve('Email send successfully to your email');
                });

mailerconfig support

Hey,

Have you remove the mailerconfig.ts support for temporarily or permanently? It was a good and easy to use configuration till this release.

Thanks

tano

Inline CSS

Feature Request

I am proposing to add a new functionality that makes the css inline because most email providers only support inline css.

How i can use static served files in mail hbs template?

I am trying to use static files served by nest app in my email hbs template.
Here is my appModule.ts:

import { join } from 'path';
import { HttpExceptionFilter } from '@shared/filters/http-exception.filter';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  const host = AppModule.isDev ? `${AppModule.host}:${AppModule.port}` : AppModule.host;

  [...]

  app
    .enableCors()
    .useGlobalFilters(new HttpExceptionFilter())
    .setBaseViewsDir(join(__dirname, '...', 'views'))
    .useStaticAssets(join(__dirname, '..', 'public'), { prefix: '/assets/' })
    .setViewEngine('hbs');
  await app.listen(AppModule.port);
}
bootstrap();

I load mailer that way:

MailerModule.forRootAsync({
      useFactory: () => ({
        transport: {
          host: 'localhost',
          port: 1025,
          secure: false,
          ignoreTLS: true,
        },
        defaults: {
          from: 'my-team" <[email protected]>',
        },
        template: {
          dir: __dirname + '/mails',
          adapter: new HandlebarsAdapter(),
          options: {
            strict: true,
          },
        },
      }),
    }),

I would like to load files from served static files.

Thanks

I can't send email via mail mailer

Hello I am new at Nest.js and I am wondering am I missing some configuration to send e-mail ?

"dependencies": {
"@nest-modules/mailer": "^1.1.2",
"@nestjs/common": "6.0.5",
"@nestjs/core": "6.0.5",
"@nestjs/mongoose": "5.0.0",
"@nestjs/passport": "^1.1.0",
"@nestjs/platform-express": "^6.0.5",
"class-transformer": "0.1.9",
"class-validator": "0.8.5",
"fastify-formbody": "2.0.0",
"jsonwebtoken": "^8.3.0",
"mongoose": "^5.4.18",
"passport": "^0.4.0",
"passport-http-bearer": "^1.0.1",
"passport-jwt": "^4.0.0",
"passport-ldapauth": "^2.1.2",
"reflect-metadata": "0.1.12",
"rxjs": "6.0.0",
"rxjs-compat": "6.0.0",
"typescript": "2.6.2"

}

My app module:

@module({
imports: [SectionModule, ProjectsModule, TestrailModule, CypressModule, MailerModule.forRoot({
transport: 'smtps://bootspring1:[email protected]',
template: {
adapter: new PugAdapter(), // or new PugAdapter()
options: {
strict: true,
},
},
})],
})

My example mail service
import { Injectable } from '@nestjs/common';
import {MailerService} from '@nest-modules/mailer';

@Injectable()
export class ExampleService {
constructor(private readonly mailerService: MailerService) {}

public example3(): void {
    this
        .mailerService
        .sendMail({
            to: '[email protected]',
            from: '[email protected]',
            subject: 'Testing Nest Mailermodule with template โœ”',
            text: 'Text',
        })
        .then(() => {})
        .catch(() => {});
}

}

I want to send mail from my email adress [email protected] to someone..

Can please someone help?

.hbs files are not copied to dist folder

Node.js 10.16.0
@nest-modules/mailer 1.1.3
nestjs 6.5.2

When sending an email using handlebars I get the following error:

[Nest] 26182   - 2019-07-29 3:41 PM   [ExceptionsHandler] ENOENT: no such file or directory, open '/var/www/html/backend-api/dist/common/templates/emails/resetPassword.hbs' +1411ms
[0] Error: ENOENT: no such file or directory, open '/var/www/html/backend-api/dist/common/templates/emails/resetPassword.hbs'
[0]     at Object.openSync (fs.js:443:3)
[0]     at Object.readFileSync (fs.js:343:35)
[0]     at HandlebarsAdapter.compile (/var/www/html/backend-api/node_modules/@nest-modules/mailer/dist/adapters/handlebars.adapter.js:19:37)
[0]     at MailerService.transporter.use (/var/www/html/backend-api/node_modules/@nest-modules/mailer/dist/mailer.service.js:44:40)
[0]     at processPlugins (/var/www/html/backend-api/node_modules/nodemailer/lib/mailer/index.js:279:13)
[0]     at err (/var/www/html/backend-api/node_modules/nodemailer/lib/mailer/index.js:283:17)
[0]     at Mail._convertDataImages (/var/www/html/backend-api/node_modules/nodemailer/lib/mailer/index.js:387:20)
[0]     at Mail._defaultPlugins.compile.args (/var/www/html/backend-api/node_modules/nodemailer/lib/mailer/index.js:31:41)
[0]     at processPlugins (/var/www/html/backend-api/node_modules/nodemailer/lib/mailer/index.js:279:13)
[0]     at Mail._processPlugins (/var/www/html/backend-api/node_modules/nodemailer/lib/mailer/index.js:287:9)

Mailer config

MailerModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: async (configService: ConfigService) => ({
    transport: `smtps://${configService.get(
      'MAILER_EMAIL',
    )}:${configService.get('MAILER_PASSWORD')}@${configService.get(
      'MAILER_HOST',
    )}`,
    defaults: {
      from: '"nest-modules" <[email protected]>',
    },
    template: {
      dir: path.join(__dirname, 'common/templates/emails'),
      adapter: new HandlebarsAdapter(),
      options: {
        strict: true,
      },
    },
  }),
  inject: [ConfigService],
})

Mailer works locally, but doesn't work in prod

Hi.

Mailer works perfectly when I start the app locally with the below command.
"start": "ts-node -r tsconfig-paths/register src/main.ts",

But the mail is not sent out if I start the app with the below command.
"prestart:prod": "rimraf dist && npm run build",
"start:prod": "node dist/main.js",

Could you let me know there is any solution for it?

package.json

{
  "name": "a",
  "version": "0.0.1",
  "description": "",
  "author": "",
  "license": "MIT",
  "scripts": {
    "build": "rimraf dist && tsc -p tsconfig.build.json",
    "format": "prettier --write \"src/**/*.ts\"",
    "start": "ts-node -r tsconfig-paths/register src/main.ts",
    "start:dev": "concurrently --handle-input \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.build.json\" ",
    "start:debug": "nodemon --config nodemon-debug.json",
    "prestart:prod": "rimraf dist && npm run build",
    "start:prod": "node dist/main.js",
    "lint": "tslint -p tsconfig.json -c tslint.json",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },
  "dependencies": {
    "@nest-modules/mailer": "^1.1.3",
    "@nestjs/common": "^6.0.0",
    "@nestjs/core": "^6.0.0",
    "@nestjs/platform-express": "^6.0.0",
    "@types/json2csv": "^4.5.0",
    "dotenv": "^8.0.0",
    "json2csv": "^4.5.1",
    "moment": "^2.24.0",
    "nest-schedule": "^0.6.0",
    "nodemailer": "^6.3.0",
    "reflect-metadata": "^0.1.12",
    "rimraf": "^2.6.2",
    "rxjs": "^6.3.3"
  },
  "devDependencies": {
    "@nestjs/testing": "^6.0.0",
    "@types/express": "^4.16.0",
    "@types/jest": "^23.3.13",
    "@types/node": "^10.12.18",
    "@types/supertest": "^2.0.7",
    "concurrently": "^4.1.0",
    "jest": "^24.9.0",
    "nodemon": "^1.19.1",
    "prettier": "^1.15.3",
    "supertest": "^3.4.1",
    "ts-jest": "^24.0.2",
    "ts-node": "8.1.0",
    "tsconfig-paths": "3.8.0",
    "tslint": "5.16.0",
    "typescript": "3.4.3",
    "wait-on": "^3.2.0"
  },
  "jest": {
    "moduleFileExtensions": [
      "js",
      "json",
      "ts"
    ],
    "rootDir": "src",
    "testRegex": ".spec.ts$",
    "transform": {
      "^.+\\.(t|j)s$": "ts-jest"
    },
    "coverageDirectory": "../coverage",
    "testEnvironment": "node"
  }
}
@Module({
  imports: [
    HttpModule,
    MailerModule.forRoot({
      transport: {
        secureConnection: false,
        host: 'smtp.office365.com',
        port: '587',
        auth: { user: '[email protected]', pass: 'password' },
        tls: { ciphers: 'SSLv3' },
      },
      template: {
        dir: __dirname + '/templates',
        adapter: new HandlebarsAdapter(), // or new PugAdapter()
        options: {
          strict: true,
        },
      },
    }),
  ],
  controllers: [
    AppController,
  ],
  providers: [
    AppService,
  ],
})

EJS support?

Hey. I'd be happy to add support for EJS templates. Would you be interested in such PR if I'd sent it?

Build fail with no implicit any

Hello people,

I don't know if this was because i update the mailer module, but the following error is happening when try to run or execute the production build.

image

If I disable the noImplicitAny flag in tsconfig.json, everything works fine.

My tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "noImplicitAny": true,
    "noImplicitReturns": false,
    "noUnusedParameters": false,
    "paths": {
      "@atividades/*": [ "./src/academico/atividades/*", ],
      "@documentos/*": [ "./src/academico/documentos/*"],
      "@config/*": [ "./src/config/*"],
      "@utils": [ "./src/utils"]
    }
  },
  "exclude": ["node_modules", "dist"]
}

I note that mailer module don't have a .d.ts file, this can be the reason of the error ?

nodemailer types

Error: Argument of type '{ to: string; replyTo: string; from: string; subject: string; template: string; context: { message: string; }; }' is not assignable to parameter of type 'ISendMailOptions'.
Object literal may only specify known properties, and 'replyTo' does not exist in type 'ISendMailOptions';

i found problem here ('/mailer/dist/interfaces/send-mail-options.interface.d.ts'):

import { SendMailOptions } from 'nodemailer';
export interface ISendMailOptions extends SendMailOptions {
    to?: string;
    from?: string;
    subject?: string;
    text?: string;
    html?: string;
    template?: string;
    context?: {
        [name: string]: any;
    };
}

The sendMailOptions interface does not exist.

Possible solution: It seems to me that you need to add @types/nodemailer in the package.json of your module

Incorrect template.options documentation / types

The README gives the following example for template.options:

template: {
  dir: __dirname + '/templates',
  adapter: new HandlebarsAdapter(), // or new PugAdapter()
  options: {
    debug: true,
    doctype: 'html',
  },
},

There appear to be several issues with this:

  • MailerOptions declares options as { [name: string]: string; }, meaning that any booleans including the debug in the example or the real-world strict become type errors
  • To my understanding options is passed to handlebars.compile, which according to this documentation does not appear to accept either debug or doctype options but the example is showing usage of handlebars.

Demo

Might be excellent to have a working demo, especially if it could be with a contact form and any front-end framework (e.g. Angular). A good starting point could be this project, where Angular, Nest and Nx workspace are already set up, just making a simple contact form with the mailer module would be missing.

handlebars & pug deps

Make pug & handlebars as optional dependencies, i don't want to keep both if i use only one.

Error: "route" not defined in [object Object] - 8:31

Hi,

I set up Nest Mailer with handlebars, i followed the documentation.
But i get this error: Error: "route" not defined in [object Object] - 8:31

Here my template setup:
template: { dir: './src/views/', adapter: new HandlebarsAdapter(), options: { strict: true, }, }

Hope you can help, i stuck on this.

[feature request] Html templating

It could be nice to add a support for html templating with handlebars or something.
I think it s current to use a tool such Email fundation to generate an email template that will render correctly an almost all mail client.
Creating a pug template with td tr... by hand is a pain.

Unexpected token export (mailerconfig.ts)

Hi guys,

When I run my project in production environment I have this issue:

 node dist/server/src/main.js

C:\Users\kevin\Documents\GitHub\backhoe\server\mailerconfig.ts:1
(function (exports, require, module, __filename, __dirname) { export = {
                                                              ^^^^^^

SyntaxError: Unexpected token export
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

Is there another way to declare the config using a file?

Thanks!

[Feature request] Support multiple transports

I have multiple mailgun transports (to send from several domains) and I couldn't realize how to make MailerModule to produce several transports.

I saw description of dynamic modules on docs.nestjs, but as far as i can see - this doesn't apply to MailerModule.

NPM audit: High vulnerability

NPM audit points to a high vulnerability when using the newest version available on NPM (1.3.9):

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ High          โ”‚ Insufficient Entropy                                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Package       โ”‚ cryptiles                                                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Patched in    โ”‚ >=4.1.2                                                      โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Dependency of โ”‚ @nest-modules/mailer                                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Path          โ”‚ @nest-modules/mailer > css-inliner > less > request > hawk > โ”‚
โ”‚               โ”‚ cryptiles                                                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ More info     โ”‚ https://npmjs.com/advisories/1464                            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

TypeError: Converting circular structure to JSON

Thanks for your work, but I encountered issue:

TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at ModuleTokenFactory.getDynamicMetadataToken (C:\www\project\node_modules\@nestjs\core\injector\module-token-factory.js:16:45)
    at ModuleTokenFactory.create (C:\www\project\node_modules\@nestjs\core\injector\module-token-factory.js:10:27)
    at NestContainer.addModule (C:\www\project\node_modules\@nestjs\core\injector\container.js:41:47)
    at DependenciesScanner.storeModule (C:\www\project\node_modules\@nestjs\core\scanner.js:31:24)
    at DependenciesScanner.scanForModules (C:\www\project\node_modules\@nestjs\core\scanner.js:21:14)
    at importedModules.map.innerModule (C:\www\project\node_modules\@nestjs\core\scanner.js:24:18)
    at Array.map (<anonymous>)
    at DependenciesScanner.scanForModules (C:\www\project\node_modules\@nestjs\core\scanner.js:23:25)
    at DependenciesScanner.scan (C:\www\project\node_modules\@nestjs\core\scanner.js:16:14)

Steps for reproducing:

  1. git clone https://github.com/nestjs/typescript-starter.git project
  2. cd project
  3. npm i
  4. npm install --save @nest-modules/mailer
  5. npm install --save nodemailer-mandrill-transport
  6. app.module.ts:
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { MailerModule } from '@nest-modules/mailer';

@Module({
  imports: [
    MailerModule.forRoot(),
  ],
  controllers: [AppController],
  components: [],
})
export class AppModule {}
  1. mailerconfig.ts:
import * as mandrillTransport from 'nodemailer-mandrill-transport';

export = {
  transport: mandrillTransport({
    auth: {
      api_key: 'key'
    }
  }),
  defaults: {
    from:'"nest-mailer" <[email protected]>',
  },
  templateDir: './src/common/email-templates'
}

How I can resolve it? Thanks for help.

Rename the module

We have decided to rename the module, for permission problems in npm, we regret the percanses

[ENHANCEMENT] CC & TO PARAMS CAN THEY BE ARRAYS TO SUPPORT MULTIPLE RECIPIENTS

Nodemailer allows you to pass an array in the TO and CC field is it possible to get this behaviour in NestJs Mailer

import { SendMailOptions } from "nodemailer";
export interface ISendMailOptions extends SendMailOptions {
    to?: string[]; // <--
    cc?: string[]; // <--
    from?: string;
    replyTo?: string;
    subject?: string;
    text?: string;
    html?: string;
    template?: string;
    context?: {
        [name: string]: any;
    };
    attachments?: {
        filename: string;
        contents?: any;
        path?: string;
        contentType?: string;
        cid: string;
    }[];
}

Dependency security vulnerabilities

Hello people,

Some security vulnerabilities was reported by npm audit on the mailer module

High Insufficient Entropy
Package cryptiles
Patched in >=4.1.2
Dependency of @nest-modules/mailer
Path @nest-modules/mailer > css-inliner > less > request > hawk > cryptiles
More info https://npmjs.com/advisories/1464

Moderate Prototype Pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of @nest-modules/mailer
Path @nest-modules/mailer > css-inliner > less > request > hawk > boom > hoek
More info https://npmjs.com/advisories/566

Moderate Prototype Pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of @nest-modules/mailer
Path @nest-modules/mailer > css-inliner > less > request > hawk > cryptiles > boom > hoek
More info https://npmjs.com/advisories/566

Moderate Prototype Pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of @nest-modules/mailer
Path @nest-modules/mailer > css-inliner > less > request > hawk > hoek
More info https://npmjs.com/advisories/566

Moderate Prototype Pollution
Package hoek
Patched in > 4.2.0 < 5.0.0 || >= 5.0.3
Dependency of @nest-modules/mailer
Path @nest-modules/mailer > css-inliner > less > request > hawk > sntp > hoek
More info https://npmjs.com/advisories/566

How to just change the port and security options on a transport?

I have a simple unauthenticated transport on a linux server that I want to use. All I need to do change the port and secure options on the transport but I am not sure where to do it. I tried to change them in the defaults section but that did not work. I would like to do it in the MailerModule section of the app.module.ts if possible and not have to dig into the NodeMailer stuff.
Thanks in advance.

Is there a reason why v1.2.0 release is not on NPM/Yarn?

I want to use nodemailer.createTransport() so I can implement nodemailer-mailgun-transport in the transport field inside MailerModule but I can't seem to be able to go forward because the current release won't support it. However, I noticed that release 1.2.0 should have the changes required for me to implement this.

Is there a reason that release is not yet on the respective package managers? Is there another way I can get these changes to make this work?

Thanks!

Argument of type is not assignable to parameter of type 'ISendMailOptions'

Hello, trying to update the package to use with NestJS V6

Version: "@nest-modules/mailer": "^1.1.2"

Here is my config

        imports: [
            MailerModule.forRoot(
                {
                    transport: `smtps://${process.env.MAIL_USER}:${process.env.MAIL_PASS}@${process.env.MAIL_HOST}`,
                    defaults:
                    {
                        from: `"System Administrator" <${process.env.MAIL_FROM}>`,
                    }
                }
            )
        ],

Here is where the error is occuring

        return this.mailerService.sendMail(
            {
                to: user.email,
                subject,
                text,
            }
        );

Here is the error I am receiving from the TS compiler:

src/user/user.service.ts:51:17 - error TS2345: Argument of type '{ to: string; subject: string; text: string; }' is not assignable to parameter of type 'ISendMailOptions'.
  Object literal may only specify known properties, and 'to' does not exist in type 'ISendMailOptions'.

51                 to: user.email,
                   ~~~~~~~~~~~~~~

    at createTSError (C:\Users\USERNAME\Development\xhauler\server\node_modules\ts-node\src\index.ts:226:12)
    at getOutput (C:\Users\USERNAME\Development\xhauler\server\node_modules\ts-node\src\index.ts:335:40)
    at Object.compile (C:\Users\USERNAME\Development\xhauler\server\node_modules\ts-node\src\index.ts:368:11)
    at Module.m._compile (C:\Users\USERNAME\Development\xhauler\server\node_modules\ts-node\src\index.ts:414:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\Users\USERNAME\Development\xhauler\server\node_modules\ts-node\src\index.ts:417:12)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)

Example was working earlier with Nest 5.4 and V1.0.3

Am I missing a step in the migration process?

Regards

Import from files

Feature Request

Proposal

I am proposing the idea of importing other files into template.

Suggested Syntax

{{ @import 'style.css' }}

{{ @import 'header.hbs' }}
...
{{ @import 'footer.hbs' }}

Motivation Behind

  • Include partial templates into template
  • Include css files into the template

From field, are you able to send mail with a different email address then the smtp server's?

Hey!

I'm wondering if you are available to send a mail by an smtp server with a different e-mail address then what is really sent from. Generally speaking, I know it's prohibited in order not to be able to send phishing or any other destructive emails, but it would be very useful for sending out contact forms:

Let's say you have your transport declared as this:

smtps://[email protected]:[email protected]

If a user sends an e-mail through contact form, it would be really good if the smtp server could send an email to itself but with in the user's name and e-mail address like:

from: "User Someone" <[email protected]>

instead of:

from: "me" <[email protected]>

I know that this - in theory - should be achievable as I've done it by PHP mailer plugin, but of course, in php environment.

Any guesses if it's possible?

Nest can't resolve dependencies of the MailerService (?). Please make sure that the argument at index [0] is available in the UserModule context

I declare Mailer module in my AppModule:

 MailerModule.forRoot({
            transport: `smtps://${configService.get('MAIL_USER')}:${configService.get('MAIL_PASSWORD')}@${configService.get('MAIL_SMTP_HOST')}`,
            defaults: {
                from: '"test" <[email protected]>',
            },
            template: {
                dir: __dirname + '/templates',
                adapter: new HandlebarsAdapter(), // or new PugAdapter()
                options: {
                    strict: true,
                },
            },
        }),

Then in UserService:

constructor(private readonly mailerService: MailerService) {}

I have a problem with circular dependency but when I try to fix throw error:

Nest can't resolve dependencies of the UserService (?). Please make sure that the argument MailerService at index [0] is available in the UserModule context.

Any help?

Expand documentation and ISendMailOptions with attachments

I managed to deal with applying attachments to the mail with the help of the nodemailer documentation but it would be really nice for newcomers to actually know about it from the nest-modules/mailer documentation.

The iSendMailOptions should be extended with something similiar to this:

export interface ISendMailOptions extends SendMailOptions {
    to?: string;
    from?: string;
    subject?: string;
    text?: string;
    html?: string;

    template?: string;
    context?: {
        [name: string]: any;
    };
    attachments?: {
        filename: string,
        content?: Stream,
        path?: string,
        contentType: string
    }
}

And there could be a documentation for it like in the nodemailer documentation. Other than that, love this package!

1.1.3 broke passing Address type objects in from/to/cc/etc...

This patch release change is actually a bug/breaking change.

Mail.Options includes from?: string | Address;, to?: string | Address | Array<string | Address>;, etc... but this change locks the options down so that only strings are accepted.

Before this patch release I had code with from: { name: 'My Site', address: this.confirmEmail }, which after upgrading now instead emits a TypeScript error of Type '{ name: string; address: string; }' is not assignable to type 'string'.

Published npm package (0.4.1) does not match source

The currently published npm package was release 4 months ago. There were a few changes in the last month that have not been pushed out to npm.

cat node_modules/@nest-modules/mailer/package.json | grep version
  "version": "0.4.1",
cat node_modules/@nest-modules/mailer/dist/interfaces/mailer-options.interface.d.ts
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
export interface MailerModuleOptions {
    transport?: any;
    defaults?: any;
    templateDir?: string;
    templateOptions?: TemplateEngineOptions;
}
export interface TemplateEngineOptions {
    engine?: string;
    engineAdapter?: Function;
    precompiledTemplates?: {
        [templateName: string]: (context: any) => any;
    };
}
export interface MailerOptionsFactory {
    createMailerOptions(): Promise<MailerModuleOptions> | MailerModuleOptions;
}
export interface MailerModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
    useExisting?: Type<MailerOptionsFactory>;
    useClass?: Type<MailerOptionsFactory>;
    useFactory?: (...args: any[]) => Promise<MailerModuleOptions> | MailerModuleOptions;
    inject?: any[];
}
export declare type RenderCallback = (err?: any, body?: string) => any;

Note that the engineConfig type is missing from TemplateEngineOptions

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.