Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation regarding MJML usage #1072

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions docs/mailer.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,108 @@ Use `.pug`, `.ejs` or `.hbs` depending on the template engine you use:
}
```

### Using MJML

You can use [mjml](https://mjml.io/) to create responsive emails with the `MjmlAdapter` adapter. The templates themselves still need to be pre-rendered with pug, handlebars or ejs.

For all 3 template engines you have to use the `inlineCssEnabled` option to disable css inlining. For handlebars you also have to pass in a helpers object to the `handlebar` option.

<!--DOCUSAURUS_CODE_TABS-->
<!--Pug-->

```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';
import { MjmlAdapter } from "@nestjs-modules/mailer/dist/adapters/mjml.adapter";

@Module({
imports: [
MailerModule.forRoot({
transport: {
host: 'localhost',
port: 1025,
ignoreTLS: true,
secure: false,
},
defaults: {
from: '"nest-modules" <noreply@localhost>',
},
preview: true,
template: {
dir: process.cwd() + '/src/template/',
adapter: new MjmlAdapter('pug', { inlineCssEnabled: false }),
},
}),
],
})
export class AppModule {}
```

<!--Handlebars-->

```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';
import { MjmlAdapter } from "@nestjs-modules/mailer/dist/adapters/mjml.adapter";

@Module({
imports: [
MailerModule.forRoot({
transport: {
host: 'localhost',
port: 1025,
ignoreTLS: true,
secure: false,
},
defaults: {
from: '"nest-modules" <noreply@localhost>',
},
preview: true,
template: {
dir: process.cwd() + '/src/template/',
adapter: new MjmlAdapter(
'handlebars',
{ inlineCssEnabled: false },
{ handlebar: { helper: {} } },
),
},
}),
],
})
export class AppModule {}
```

<!--Ejs-->

```javascript
//app.module.ts
import { Module } from '@nestjs/common';
import { MailerModule } from '@nestjs-modules/mailer';
import { MjmlAdapter } from "@nestjs-modules/mailer/dist/adapters/mjml.adapter";

@Module({
imports: [
MailerModule.forRoot({
transport: {
host: 'localhost',
port: 1025,
ignoreTLS: true,
secure: false,
},
defaults: {
from: '"nest-modules" <noreply@localhost>',
},
preview: true,
template: {
dir: process.cwd() + '/src/template/',
adapter: new MjmlAdapter('ejs', { inlineCssEnabled: false }),
},
}),
],
})
export class AppModule {}
```

<!--END_DOCUSAURUS_CODE_TABS-->
Loading