forked from nest-modules/mailer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*/node_modules | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM node:lts | ||
|
||
WORKDIR /app/website | ||
|
||
EXPOSE 3000 35729 | ||
COPY ./docs /app/docs | ||
COPY ./website /app/website | ||
RUN yarn install | ||
|
||
CMD ["yarn", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "3" | ||
|
||
services: | ||
docusaurus: | ||
build: . | ||
ports: | ||
- 3000:3000 | ||
- 35729:35729 | ||
volumes: | ||
- ./docs:/app/docs | ||
- ./website/blog:/app/website/blog | ||
- ./website/core:/app/website/core | ||
- ./website/i18n:/app/website/i18n | ||
- ./website/pages:/app/website/pages | ||
- ./website/static:/app/website/static | ||
- ./website/sidebars.json:/app/website/sidebars.json | ||
- ./website/siteConfig.js:/app/website/siteConfig.js | ||
working_dir: /app/website |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
id: doc2 | ||
title: document number 2 | ||
--- | ||
|
||
This is a link to [another document.](doc3.md) | ||
This is a link to an [external page.](http://www.example.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
id: doc3 | ||
title: This is document number 3 | ||
--- | ||
|
||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ac euismod odio, eu consequat dui. Nullam molestie consectetur risus id imperdiet. Proin sodales ornare turpis, non mollis massa ultricies id. Nam at nibh scelerisque, feugiat ante non, dapibus tortor. Vivamus volutpat diam quis tellus elementum bibendum. Praesent semper gravida velit quis aliquam. Etiam in cursus neque. Nam lectus ligula, malesuada et mauris a, bibendum faucibus mi. Phasellus ut interdum felis. Phasellus in odio pulvinar, porttitor urna eget, fringilla lectus. Aliquam sollicitudin est eros. Mauris consectetur quam vitae mauris interdum hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
|
||
Duis et egestas libero, imperdiet faucibus ipsum. Sed posuere eget urna vel feugiat. Vivamus a arcu sagittis, fermentum urna dapibus, congue lectus. Fusce vulputate porttitor nisl, ac cursus elit volutpat vitae. Nullam vitae ipsum egestas, convallis quam non, porta nibh. Morbi gravida erat nec neque bibendum, eu pellentesque velit posuere. Fusce aliquam erat eu massa eleifend tristique. | ||
|
||
Sed consequat sollicitudin ipsum eget tempus. Integer a aliquet velit. In justo nibh, pellentesque non suscipit eget, gravida vel lacus. Donec odio ante, malesuada in massa quis, pharetra tristique ligula. Donec eros est, tristique eget finibus quis, semper non nisl. Vivamus et elit nec enim ornare placerat. Sed posuere odio a elit cursus sagittis. | ||
|
||
Phasellus feugiat purus eu tortor ultrices finibus. Ut libero nibh, lobortis et libero nec, dapibus posuere eros. Sed sagittis euismod justo at consectetur. Nulla finibus libero placerat, cursus sapien at, eleifend ligula. Vivamus elit nisl, hendrerit ac nibh eu, ultrices tempus dui. Nam tellus neque, commodo non rhoncus eu, gravida in risus. Nullam id iaculis tortor. | ||
|
||
Nullam at odio in sem varius tempor sit amet vel lorem. Etiam eu hendrerit nisl. Fusce nibh mauris, vulputate sit amet ex vitae, congue rhoncus nisl. Sed eget tellus purus. Nullam tempus commodo erat ut tristique. Cras accumsan massa sit amet justo consequat eleifend. Integer scelerisque vitae tellus id consectetur. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
id: doc4 | ||
title: Other Document | ||
--- | ||
|
||
this is another document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
id: doc5 | ||
title: Fifth Document | ||
--- | ||
|
||
Another one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,289 @@ | ||
--- | ||
id: mailer | ||
title: How to use? | ||
sidebar_label: How to use? | ||
--- | ||
|
||
Check this documentation for how to use ```@nestjs/mailer```. | ||
|
||
## Install | ||
|
||
```sh | ||
yarn add @nestjs/mailer | ||
#or | ||
npm install --save @nestjs/mailer | ||
``` | ||
|
||
## Module | ||
|
||
You can create a module with mailer as follows | ||
|
||
### Configuration | ||
|
||
Import the MailerModule into the root AppModule. | ||
|
||
<!--DOCUSAURUS_CODE_TABS--> | ||
<!--Pug--> | ||
|
||
```javascript | ||
//app.module.ts | ||
import { Module } from '@nestjs/common'; | ||
import { PugAdapter, MailerModule } from '@nestjs-modules/mailer'; | ||
|
||
@Module({ | ||
imports: [ | ||
MailerModule.forRoot({ | ||
transport: 'smtps://[email protected]:[email protected]', | ||
defaults: { | ||
from:'"nest-modules" <[email protected]>', | ||
}, | ||
template: { | ||
dir: __dirname + '/templates', | ||
adapter: new PugAdapter(), | ||
options: { | ||
strict: true, | ||
}, | ||
}, | ||
}), | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
<!--Handlebars--> | ||
```javascript | ||
//app.module.ts | ||
import { Module } from '@nestjs/common'; | ||
import { HandlebarsAdapter, MailerModule } from '@nestjs-modules/mailer'; | ||
|
||
@Module({ | ||
imports: [ | ||
MailerModule.forRoot({ | ||
transport: 'smtps://[email protected]:[email protected]', | ||
defaults: { | ||
from:'"nest-modules" <[email protected]>', | ||
}, | ||
template: { | ||
dir: __dirname + '/templates', | ||
adapter: new HandlebarsAdapter(), | ||
options: { | ||
strict: true, | ||
}, | ||
}, | ||
}), | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
<!--END_DOCUSAURUS_CODE_TABS--> | ||
|
||
### Async configuration | ||
|
||
Of course, it is possible to use an async configuration: | ||
|
||
<!--DOCUSAURUS_CODE_TABS--> | ||
|
||
<!--Pug--> | ||
```javascript | ||
//app.module.ts | ||
import { Module } from '@nestjs/common'; | ||
import { PugAdapter, MailerModule } from '@nestjs-modules/mailer'; | ||
|
||
@Module({ | ||
|
||
imports: [ | ||
MailerModule.forRootAsync({ | ||
useFactory: () => ({ | ||
transport: 'smtps://[email protected]:[email protected]', | ||
defaults: { | ||
from:'"nest-modules" <[email protected]>', | ||
}, | ||
template: { | ||
dir: __dirname + '/templates', | ||
adapter: new PugAdapter(), | ||
options: { | ||
strict: true, | ||
}, | ||
}, | ||
}), | ||
}), | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
<!--Handlebars--> | ||
```javascript | ||
//app.module.ts | ||
import { Module } from '@nestjs/common'; | ||
import { HandlebarsAdapter, MailerModule } from '@nestjs-modules/mailer'; | ||
|
||
@Module({ | ||
imports: [ | ||
MailerModule.forRootAsync({ | ||
useFactory: () => ({ | ||
transport: 'smtps://[email protected]:[email protected]', | ||
defaults: { | ||
from:'"nest-modules" <[email protected]>', | ||
}, | ||
template: { | ||
dir: __dirname + '/templates', | ||
adapter: new HandlebarsAdapter(), | ||
options: { | ||
strict: true, | ||
}, | ||
}, | ||
}), | ||
}), | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
<!--END_DOCUSAURUS_CODE_TABS--> | ||
|
||
### Enable handlebars partials | ||
|
||
```typescript | ||
import * as path from 'path'; | ||
import { Module } from '@nestjs/common'; | ||
import { BullModule } from 'nest-bull'; | ||
import { MailerModule, HandlebarsAdapter } from '@nestjs-modules/mailer'; | ||
import { mailBullConfig } from '../../config/mail'; | ||
import { MailService } from './mail.service'; | ||
import { MailController } from './mail.controller'; | ||
import { MailQueue } from './mail.queue'; | ||
|
||
const bullModule = BullModule.forRoot(mailBullConfig); | ||
@Module({ | ||
imports: [ | ||
bullModule, | ||
MailerModule.forRoot({ | ||
defaults: { | ||
from: '"No Reply" <[email protected]>', | ||
}, | ||
template: { | ||
dir: path.join(process.env.PWD, 'templates/pages'), | ||
adapter: new HandlebarsAdapter(), | ||
options: { | ||
strict: true, | ||
}, | ||
}, | ||
options: { | ||
partials: { | ||
dir: path.join(process.env.PWD, 'templates/partials'), | ||
options: { | ||
strict: true, | ||
}, | ||
} | ||
} | ||
}), | ||
], | ||
controllers: [MailController], | ||
providers: [MailService, MailQueue], | ||
exports: [bullModule], | ||
}) | ||
export class MailModule {} | ||
``` | ||
|
||
## Service | ||
|
||
```typescript | ||
import { Injectable } from '@nestjs/common'; | ||
import { MailerService } from '@nestjs-modules/mailer'; | ||
|
||
@Injectable() | ||
export class ExampleService { | ||
constructor(private readonly mailerService: MailerService) {} | ||
} | ||
``` | ||
|
||
MailerProvider exports the `sendMail()` function to which you can pass the message options (sender, email subject, recipient, body content, etc) | ||
|
||
`sendMail()` accepts the same fields as [nodemailer email message](https://nodemailer.com/message/) | ||
|
||
<!--DOCUSAURUS_CODE_TABS--> | ||
<!--Example 1--> | ||
```typescript | ||
import { Injectable } from '@nestjs/common'; | ||
import { MailerService } from '@nestjs-modules/mailer'; | ||
|
||
@Injectable() | ||
export class ExampleService { | ||
constructor(private readonly mailerService: MailerService) {} | ||
|
||
public example(): void { | ||
this | ||
.mailerService | ||
.sendMail({ | ||
to: '[email protected]', // list of receivers | ||
from: '[email protected]', // sender address | ||
subject: 'Testing Nest MailerModule ✔', // Subject line | ||
text: 'welcome', // plaintext body | ||
html: '<b>welcome</b>', // HTML body content | ||
}) | ||
.then(() => {}) | ||
.catch(() => {}); | ||
} | ||
|
||
} | ||
``` | ||
|
||
<!--Example 2--> | ||
```typescript | ||
import { Injectable } from '@nestjs/common'; | ||
import { MailerService } from '@nestjs-modules/mailer'; | ||
|
||
@Injectable() | ||
export class ExampleService { | ||
constructor(private readonly mailerService: MailerService) {} | ||
|
||
public example(): void { | ||
this | ||
.mailerService | ||
.sendMail({ | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'Testing Nest Mailermodule with template ✔', | ||
template: 'welcome', // The `.pug` or `.hbs` extension is appended automatically. | ||
context: { // Data to be sent to template engine. | ||
code: 'cf1a3f828287', | ||
username: 'john doe', | ||
}, | ||
}) | ||
.then(() => {}) | ||
.catch(() => {}); | ||
} | ||
|
||
} | ||
``` | ||
|
||
<!--Example 3--> | ||
```typescript | ||
import { Injectable } from '@nestjs/common'; | ||
import { MailerService } from '@nestjs-modules/mailer'; | ||
|
||
@Injectable() | ||
export class ExampleService { | ||
constructor(private readonly mailerService: MailerService) {} | ||
|
||
public example(): void { | ||
this | ||
.mailerService | ||
.sendMail({ | ||
to: '[email protected]', | ||
from: '[email protected]', | ||
subject: 'Testing Nest Mailermodule with template ✔', | ||
template: __dirname + '/welcome', // The `.pug` or `.hbs` extension is appended automatically. | ||
context: { // Data to be sent to template engine. | ||
code: 'cf1a3f828287', | ||
username: 'john doe', | ||
}, | ||
}) | ||
.then(() => {}) | ||
.catch(() => {}); | ||
} | ||
} | ||
``` | ||
|
||
<!--END_DOCUSAURUS_CODE_TABS--> | ||
|
Oops, something went wrong.