Skip to content
Closed
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion docs/mailer.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,11 @@ Use `.pug`, `.ejs` or `.hbs` depending on the template engine you use:

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.
**Important:** When using MJML, you **must** set `inlineCssEnabled: false` in the adapter config. This is because MJML handles its own CSS inlining internally, and having both MJML and the `@css-inline/css-inline` module process the HTML would result in duplicated or broken styles.

For handlebars you also have to pass in a helpers object to the `handlebar` option.

> **Note:** Handlebars partials can be used with MJML by configuring the `options.partials` setting in `MailerOptions`. However, the partials must be valid MJML markup since MJML will process the final compiled output.

<!--DOCUSAURUS_CODE_TABS-->
<!--Pug-->
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/ejs.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { get } from 'lodash';
import * as fs from 'fs';
import * as path from 'path';
import { inline } from '@css-inline/css-inline';

/** Interfaces **/
import { MailerOptions } from '../interfaces/mailer-options.interface';
Expand Down Expand Up @@ -60,6 +59,7 @@ export class EjsAdapter implements TemplateAdapter {
const render = (html: string) => {
if (this.config.inlineCssEnabled) {
try {
const { inline } = require('@css-inline/css-inline');
mail.data.html = inline(html, this.config.inlineCssOptions);
} catch (e) {
callback(e);
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/handlebars.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import * as fs from 'fs';
import * as path from 'path';
import * as handlebars from 'handlebars';
import { inline } from '@css-inline/css-inline';
import * as glob from 'glob';
import { get } from 'lodash';
import { HelperDeclareSpec } from 'handlebars';
Expand Down Expand Up @@ -110,6 +109,7 @@ export class HandlebarsAdapter implements TemplateAdapter {

if (this.config.inlineCssEnabled) {
try {
const { inline } = require('@css-inline/css-inline');
mail.data.html = inline(rendered, this.config.inlineCssOptions);
} catch (e) {
callback(e);
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/pug.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import * as path from 'path';
import { get } from 'lodash';
import { renderFile } from 'pug';
import { inline } from '@css-inline/css-inline';

/** Interfaces **/
import { MailerOptions } from '../interfaces/mailer-options.interface';
Expand Down Expand Up @@ -43,6 +42,7 @@ export class PugAdapter implements TemplateAdapter {

if (this.config.inlineCssEnabled) {
try {
const { inline } = require('@css-inline/css-inline');
mail.data.html = inline(body, this.config.inlineCssOptions);
} catch (e) {
callback(e);
Expand Down
5 changes: 2 additions & 3 deletions lib/mailer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class MailerService {
const transporterName = name ? ` '${name}'` : '';
if (!transporter.verify) return;
Promise.resolve(transporter.verify())
.then(() => this.mailerLogger.debug(`Transporter${transporterName} is ready`))
.then(() => this.mailerLogger.log(`Transporter${transporterName} is ready`))
.catch((error) => this.mailerLogger.error(`Error occurred while verifying the transporter${transporterName}: ${error.message}`));
}

Expand Down Expand Up @@ -171,9 +171,8 @@ export class MailerService {
addTransporter(transporterName: string, config: string | smtpTransport | smtpTransport.Options): string {
this.transporters.set(
transporterName,
this.transportFactory.createTransport(config),
this.createTransporter(config, transporterName),
);
this.initTemplateAdapter(this.templateAdapter, this.transporters.get(transporterName)!);
return transporterName;
}
}
Loading