Mail module for Nest that uses Nodemailer to deliver messages.
$ npm i --save @fastnloud/nest-mail
Import module:
import { MailModule } from '@fastnloud/nest-mail';
import { Module } from '@nestjs/common';
@Module({
imports: [MailModule],
})
export class AppModule {}
A sample .env
file looks something like this:
[email protected]
MAIL_DEFAULT_FROM_NAME=John Doe
MAIL_RECIPIENTS=
MAIL_URL=smtp://localhost:1025
import { SmtpTransporter } from '@fastnloud/nest-mail';
import { Injectable } from '@nestjs/common';
import { SentMessageInfo } from 'nodemailer';
@Injectable()
export class MailService {
constructor(private readonly smtpTransporter: SmtpTransporter) {}
async send(): Promise<void> {
this.smtpTransporter.send(
{
to: '[email protected]',
subject: `hello`,
text: 'world',
},
(error: Error | null, info: SentMessageInfo) => {
if (error) {
throw error;
}
console.log(info);
},
);
}
}
nest-mail is MIT licensed.