Skip to content

Commit

Permalink
fix: EmailServiceでインラインスタイルを適用するように
Browse files Browse the repository at this point in the history
  • Loading branch information
Esurio committed Sep 21, 2024
1 parent d3f1b0f commit 1cd0cdb
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"json5": "2.2.3",
"jsonld": "8.3.2",
"jsrsasign": "11.1.0",
"juice": "11.0.0",
"meilisearch": "0.41.0",
"mfm-js": "0.24.0",
"microformats-parser": "2.0.2",
Expand Down
23 changes: 14 additions & 9 deletions packages/backend/src/core/EmailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { URLSearchParams } from 'node:url';
import * as nodemailer from 'nodemailer';
import juice from 'juice';
import { Inject, Injectable } from '@nestjs/common';
import { validate as validateEmail } from 'deep-email-validator';
import { MetaService } from '@/core/MetaService.js';
Expand Down Expand Up @@ -61,14 +62,7 @@ export class EmailService {
} : undefined,
} as any);

try {
// TODO: htmlサニタイズ
const info = await transporter.sendMail({
from: meta.email!,
to: to,
subject: subject,
text: text,
html: `<!doctype html>
const htmlContent = `<!doctype html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -147,7 +141,18 @@ export class EmailService {
<a href="${ this.config.url }">${ this.config.host }</a>
</nav>
</body>
</html>`,
</html>`;

const inlinedHtml = juice(htmlContent);

try {
// TODO: htmlサニタイズ
const info = await transporter.sendMail({
from: meta.email!,
to: to,
subject: subject,
text: text,
html: inlinedHtml,
});

this.logger.info(`Message sent: ${info.messageId}`);
Expand Down
Loading

0 comments on commit 1cd0cdb

Please sign in to comment.